diff --git a/CHANGES.md b/CHANGES.md index b326a0139d1..3c0accaffc1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -53,6 +53,9 @@ +- Add Neovim configuration guide to editor integration docs, covering lazy.nvim, + packer.nvim, Lua configuration, and troubleshooting (#5064) + ## 26.3.1 ### Stable style diff --git a/docs/integrations/editors.md b/docs/integrations/editors.md index 3f5a99933a6..3e1ff0e9840 100644 --- a/docs/integrations/editors.md +++ b/docs/integrations/editors.md @@ -411,6 +411,89 @@ Sublime Text, Visual Studio Code and many more), you can use the Use the [Spotless](https://github.com/diffplug/spotless/tree/main/plugin-gradle) plugin. +## Neovim + +_Black_ works with Neovim using the same official plugin as Vim. The plugin +automatically detects Neovim and uses `~/.local/share/nvim/black` as the default +virtualenv location. + +### Using lazy.nvim + +For Neovim 0.8+ with [lazy.nvim](https://github.com/folke/lazy.nvim): + +```lua +{ + 'psf/black', + branch = 'stable', + ft = 'python', + config = function() + -- Configure Black settings + vim.g.black_fast = 0 + vim.g.black_linelength = 88 + + -- Format on save + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.py', + callback = function() + vim.cmd('Black') + end, + }) + end, +} +``` + +### Using packer.nvim + +```lua +use { + 'psf/black', + branch = 'stable', + ft = 'python', + config = function() + -- Format on save + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.py', + callback = function() + vim.cmd('Black') + end, + }) + end, +} +``` + +### Lua Configuration + +For `init.lua` users: + +```lua +-- All g:black_* settings +vim.g.black_fast = 0 +vim.g.black_linelength = 88 +vim.g.black_use_virtualenv = 1 +vim.g.black_virtualenv = '~/.local/share/nvim/black' + +-- Commands +vim.keymap.set('n', '', ':Black', { silent = true }) +``` + +### Troubleshooting + +**Error: Python provider not found** + +Ensure Neovim has Python 3 support: + +```vim +:checkhealth provider +``` + +Install if missing: + +```console +$ pip install pynvim +``` + +_See [Vim section](#vim) for more configuration options._ + ## Kakoune Add the following hook to your kakrc, then run _Black_ with `:format`.