Update editor setup docs about Neovim and Vim (#18324)

## Summary

I struggled to make ruff_organize_imports work and then I found out I
missed the key note about conform.nvim before because it was put in the
Vim section wrongly! So I refined them both.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
otakutyrant 2025-06-03 15:40:22 +08:00 committed by GitHub
parent 57202c1c77
commit d1cb8e2142
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -131,6 +131,63 @@ To view the trace logs between Neovim and Ruff, set the log level for Neovim's L
vim.lsp.set_log_level('debug')
```
<details>
<summary>With the <a href="https://github.com/stevearc/conform.nvim"><code>conform.nvim</code></a> plugin for Neovim.</summary>
```lua
require("conform").setup({
formatters_by_ft = {
python = {
-- To fix auto-fixable lint errors.
"ruff_fix",
-- To run the Ruff formatter.
"ruff_format",
-- To organize the imports.
"ruff_organize_imports",
},
},
})
```
</details>
<details>
<summary>With the <a href="https://github.com/mfussenegger/nvim-lint"><code>nvim-lint</code></a> plugin for Neovim.</summary>
```lua
require("lint").linters_by_ft = {
python = { "ruff" },
}
```
</details>
<details>
<summary>With the <a href="https://github.com/dense-analysis/ale">ALE</a> plugin for Neovim or Vim.</summary>
<i>Neovim (using Lua):</i>
```lua
-- Linters
vim.g.ale_linters = { python = { "ruff" } }
-- Fixers
vim.g.ale_fixers = { python = { "ruff", "ruff_format" } }
```
<i>Vim (using Vimscript):</i>
```vim
" Linters
let g:ale_linters = { "python": ["ruff"] }
" Fixers
let g:ale_fixers = { "python": ["ruff", "ruff_format"] }
```
For the fixers, <code>ruff</code> will run <code>ruff check --fix</code> (to fix all auto-fixable
problems) whereas <code>ruff_format</code> will run <code>ruff format</code>.
</details>
## Vim
The [`vim-lsp`](https://github.com/prabirshrestha/vim-lsp) plugin can be used to configure the Ruff Language Server in Vim.
@ -169,24 +226,8 @@ endfunction
Ruff is also available as part of the [coc-pyright](https://github.com/fannheyward/coc-pyright)
extension for [coc.nvim](https://github.com/neoclide/coc.nvim).
<details>
<summary>With the <a href="https://github.com/dense-analysis/ale">ALE</a> plugin for Vim or Neovim.</summary>
```vim
" Linters
let g:ale_linters = { "python": ["ruff"] }
" Fixers
let g:ale_fixers = { "python": ["ruff", "ruff_format"] }
```
For the fixers, `ruff` will run `ruff check --fix` (to fix all auto-fixable problems) whereas
`ruff_format` will run `ruff format`.
</details>
<details>
<summary>Ruff can also be integrated via <a href="https://github.com/mattn/efm-langserver">efm language server</a> in just a few lines.</summary>
<br>
Following is an example config for efm to use Ruff for linting and formatting Python files:
@ -203,38 +244,6 @@ tools:
</details>
<details>
<summary>With the <a href="https://github.com/stevearc/conform.nvim"><code>conform.nvim</code></a> plugin for Neovim.</summary>
<br>
```lua
require("conform").setup({
formatters_by_ft = {
python = {
-- To fix auto-fixable lint errors.
"ruff_fix",
-- To run the Ruff formatter.
"ruff_format",
-- To organize the imports.
"ruff_organize_imports",
},
},
})
```
</details>
<details>
<summary>With the <a href="https://github.com/mfussenegger/nvim-lint"><code>nvim-lint</code></a> plugin for Neovim.</summary>
```lua
require("lint").linters_by_ft = {
python = { "ruff" },
}
```
</details>
## Helix
Open the [language configuration file](https://docs.helix-editor.com/languages.html#languagestoml-files) for