akayj / yapf.nvim

Yapf plugin for NeoVim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yapf.nvim

NeoVim Yapf formatter plugin

Requirements

Yapf

pip install yapf

plenary.nvim

use 'nvim-lua/plenary.nvim'

Installation

-- using packer
use {
  'amirali/yapf.nvim',
  requires = {'nvim-lua/plenary.nvim'},
  config = function()
    require('yapf').setup {}
  end,
}

Configuration

...
  config = function
    require('yapf').setup {
      command = 'custom_yapf_command',
      style = 'your_preferred_style_or_path_to_config_file',
    }
  end,
...

Styles

You can choose whatever style or config file that yapf supports
Checkout here

Usage

Using command

You can run :Yapf whenever you want to format the current buffer

Automation

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

Keybind

-- in lua
vim.api.nvim_set_keymap('n', '<leader>y', ':Yapf<CR>', {})
" in vim
nmap <leader>y :Yapf<CR>

About

Yapf plugin for NeoVim


Languages

Language:Lua 84.5%Language:Vim Script 15.5%