A combination of black and isort python formatters for Neovim.
- If you're not using venv, I would recommend creating one
mkdir -p ~/.local/venv && cd ~/.local/venv
python3 -m venv nvim
nvim/bin/pip install -U pynvim black isort
- Then in your init.lua
vim.g.python3_host_prog = vim.env.HOME .. '/.local/venv/nvim/bin/python'
lazy.nvim:
{
'playwmadness/pyformat.nvim',
build = { ':UpdateRemotePlugins' },
ft = { 'python' },
}
Call :PyFormat
to format current buffer.
Alternatively there is synchronous :PyFormatSync
which can be used with autocmd like
au BufWritePre *.py,*.pyi silent! PyFormatSync
to format your python files before writing them
Defaults:
vim.g['pyformat#black#settings'] = {
line_length = 88,
fast = false,
}