17

SQL Statement indentation good practice ”似乎是编写 SQL 块的公认格式。

是否有符合此标准或至少接近此标准的 Vim 缩进/语法文件?

目前我的 Vim 留下了几乎所有东西,并且只缩进某些关键字。

4

4 回答 4

21

通过安装 python 模块sqlparse,这使得该sqlformat命令在您的终端中可用。

pip install sqlparse

从 vim 你可以使用

:%!sqlformat --reindent --keywords upper --identifiers lower -

为了附加快捷方式,pt.vimrc我在我的配置文件中添加了以下配置:

autocmd FileType sql call SqlFormatter()
augroup end
function SqlFormatter()
    set noai
    " set mappings...
    map ,pt  :%!sqlformat --reindent --keywords upper --identifiers lower -<CR>
endfunction

您可以稍微自定义 sqlformat。看

sqlformat --帮助

于 2017-04-26T13:33:25.170 回答
11

SQLUtilities : SQL 实用程序 - 格式化、生成 - 列列表、数据库过程”具有 SQL Utilities 插件,该插件功能强大。而“ How to auto-format and auto-capitalize SQL in Vim ”是一个相关的讨论。

于 2011-12-20T15:27:48.780 回答
6

如果你使用coc.nvim那么你可以添加coc-sql 扩展

于 2019-08-19T04:30:12.947 回答
5

您可以使用vim-autoformat插件:

  • vim-autoformat使用您最喜欢的插件管理器安装(我更喜欢轻量级vim-plug
  • 安装sqlparse_pip
  • 将以下行添加到您的 vim/nvim 配置中
noremap <F3> :Autoformat<CR>
let g:formatdef_sql = '"sqlformat --reindent --keywords upper - identifiers lower -"'
let g:formatters_sql = ['sql']

如果您看到此消息:vim has no support for python,您应该使用 python 支持重建您的 vim 或为 neovim安装python-client

于 2017-07-07T15:13:08.160 回答