NeoVim Yapf formatter plugin
pip install yapf
use 'nvim-lua/plenary.nvim'
-- using packer
use {
'amirali/yapf.nvim',
requires = {'nvim-lua/plenary.nvim'},
config = function()
require('yapf').setup {}
end,
}
...
config = function
require('yapf').setup {
command = 'custom_yapf_command',
style = 'your_preferred_style_or_path_to_config_file',
}
end,
...
You can choose whatever style or config file that yapf supports
Checkout here
You can run :Yapf
whenever you want to format the current buffer
You can add the line below to your config file to run formatter on save
-- in lua
vim.command [[autocmd BufWritePre *.py :Yapf]]
" in vim
autocmd BufWritePre *.py :Yapf
-- in lua
vim.api.nvim_set_keymap('n', '<leader>y', ':Yapf<CR>', {})
" in vim
nmap <leader>y :Yapf<CR>