From 55929ec762e6dc659b84521d914fb383955eeaae Mon Sep 17 00:00:00 2001 From: "Patrick C. McGinty" Date: Thu, 28 Apr 2016 15:57:04 -1000 Subject: [PATCH 1/2] Add YAPF Python formatter --- README.md | 16 ++++++++++++++++ plugin/defaults.vim | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ed0c91..3c7d3b7 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,19 @@ Here is a list of formatprograms that are supported by default, and thus will be Here is the link to the repository: https://github.com/hhatto/autopep8. And here the link to its page on the python website: http://pypi.python.org/pypi/autopep8/0.5.2. +* `yapf` for __Python__ (supports formatting ranges). + It is readily available through PIP. Most users can install with the terminal command `sudo pip install yapf` or `pip --user install yapf`. + YAPF has one optional configuration variable to control the formatter style. + For example: + + ```vim + let g:formatter_yapf_style = 'pep8' + ``` + + `pep8` is the default value, or you can choose: `google`, `facebook`, `chormium`. + + Here is the link to the repository: https://github.com/google/yapf + * `js-beautify` for __Javascript__ and __JSON__. It can be installed by running `npm install -g js-beautify`. Note that `nodejs` is needed for this to work. @@ -274,6 +287,9 @@ contact me by creating an issue in this repository. ## Change log +### April 2016 +* Add `yapf` as a secondary Python formatter. + ### March 2016 * Add more fallback options. * Don't use the option formatprg at all, to always have the possible of using the default `gq` diff --git a/plugin/defaults.vim b/plugin/defaults.vim index ff5bfcd..b8ccee2 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -37,8 +37,16 @@ function! g:DoesRangeEqualBuffer(first, last) return line('$') != a:last - a:first + 1 endfunction +" Yapf supports multiple formatter styles: pep8, google, chromium, or facebook +if !exists('g:formatter_yapf_style') + let g:formatter_yapf_style = 'pep8' +endif +if !exists('g:formatdef_yapf') + let g:formatdef_yapf = "'yapf --style={based_on_style:'.g:formatter_yapf_style.',indent_width:'.&shiftwidth.'} -l '.a:firstline.'-'.a:lastline" +endif + if !exists('g:formatters_python') - let g:formatters_python = ['autopep8'] + let g:formatters_python = ['autopep8','yapf'] endif From 199f6b2f9ddc92319d8375279e80dc4c8b30f119 Mon Sep 17 00:00:00 2001 From: "Patrick C. McGinty" Date: Fri, 29 Apr 2016 09:43:42 -1000 Subject: [PATCH 2/2] Fix 'chromium' typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c7d3b7..64a8bd4 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Here is a list of formatprograms that are supported by default, and thus will be let g:formatter_yapf_style = 'pep8' ``` - `pep8` is the default value, or you can choose: `google`, `facebook`, `chormium`. + `pep8` is the default value, or you can choose: `google`, `facebook`, `chromium`. Here is the link to the repository: https://github.com/google/yapf