Skip to content

matiasg/vim-yapf-format

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

vim-yapf-format

VIM integration for yapf.

Installation

If you use Vundle, add to your .vimrc:

Plugin 'pignacio/vim-yapf-format'

or with pathogen.vim:

cd ~/.vim/bundle
git clone git://github.com/pignacio/vim-yapf-format

Requirements

NOTE:

If yapf is not in your sys.path you have to add the following line in your .vimrc:

let g:yapf_format_yapf_location = '/path/to/yapf'

Usage

Use the YapfFormat command to format the current lines or range. Some examples:

# Reformat current line
:YapfFormat

# Reformat current visual range
:'<,'>YapfFormat

# Reformat whole file
:%YapfFormat

# In general, reformat <range>
:<range>YapfFormat

The default style is pep8. To change it, set the g:yapf_format_style (for global style) or b:yapf_format_style (for current buffer) to your preffered style. Buffer variable takes precedende over the global one, to allow single buffer overrides.

Key Bindings

I use the following key bindings to reformat the whole file in normal mode, the current line in insert mode and the current range in visual mode:

map <C-o> :%YapfFormat<CR>
imap <C-o> <ESC>:YapfFormat<CR>i
vmap <C-o> :YapfFormat<CR>

Of course, the <C-o> can be changed to any key you like ;)

Credits

This script is heavily inspired by clang-format.py

About

VIM integration for YAPF

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 50.6%
  • Vim Script 49.4%