From b8173cde8692360fb9ec6817ef2bd8133106e514 Mon Sep 17 00:00:00 2001 From: Chiel ten Brinke Date: Tue, 7 Aug 2018 11:39:02 +0200 Subject: [PATCH] Add sqlformat support. --- README.md | 3 +++ plugin/defaults.vim | 12 ++++++++++-- samples/test.sql | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 samples/test.sql diff --git a/README.md b/README.md index feb5181..f753bee 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,9 @@ Here is a list of formatprograms that are supported by default, and thus will be * `shfmt` for __Shell__. A shell formatter written in Go supporting POSIX Shell, Bash and mksh that can be installed with `go get -u mvdan.cc/sh/cmd/shfmt`. See https://github.com/mvdan/sh for more info. +* `sqlformat` for __SQL__. + Install `sqlparse` with `pip`. + ## Help, the formatter doesn't work as expected! diff --git a/plugin/defaults.vim b/plugin/defaults.vim index d464527..8c9ef7c 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -44,7 +44,7 @@ if !exists('g:formatter_yapf_style') endif if !exists('g:formatdef_yapf') let s:configfile_def = "'yapf -l '.a:firstline.'-'.a:lastline" - let s:noconfigfile_def = "'yapf --style=\"{based_on_style:'.g:formatter_yapf_style.',indent_width:'.&shiftwidth.(&textwidth ? ',column_limit:'.&textwidth : '').'}\" -l '.a:firstline.'-'.a:lastline" + let s:noconfigfile_def = "'yapf --style=\"{based_on_style:'.g:formatter_yapf_style.',indent_width:'.shiftwidth().(&textwidth ? ',column_limit:'.&textwidth : '').'}\" -l '.a:firstline.'-'.a:lastline" let g:formatdef_yapf = "g:YAPFFormatConfigFileExists() ? (" . s:configfile_def . ") : (" . s:noconfigfile_def . ")" endif @@ -452,7 +452,7 @@ endif " Fortran if !exists('g:formatdef_fprettify') - let g:formatdef_fprettify = '"fprettify --no-report-errors --indent=".&shiftwidth' + let g:formatdef_fprettify = '"fprettify --no-report-errors --indent=".shiftwidth()' endif if !exists('g:formatters_fortran') @@ -476,3 +476,11 @@ endif if !exists('g:formatters_sh') let g:formatters_sh = ['shfmt'] endif + +" SQL +if !exists('g:formatdef_sqlformat') + let g:formatdef_sqlformat = '"sqlformat --reindent --indent_width ".shiftwidth()." --keywords upper --identifiers lower -"' +endif +if !exists('g:formatters_sql') + let g:formatters_sql = ['sqlformat'] +endif diff --git a/samples/test.sql b/samples/test.sql new file mode 100644 index 0000000..ad80b71 --- /dev/null +++ b/samples/test.sql @@ -0,0 +1 @@ +selECT * FROM foo WHERE id IN (SELECT id FROM bar);