Ⅰ. 插件描述
The best PostgreSQL plugin for Vim!Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'lifepillar/pgsql'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'lifepillar/pgsql'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'lifepillar/pgsql'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/lifepillar/pgsql.vim
Ⅳ. 文档说明
# Vim PostgreSQL syntax plugin
This plugin provides syntax highlighting and auto-completion support for
PostgreSQL version 9.6 or above and for some of its extensions, including:
Besides, syntax highlighting for any language may be activated inside functions
(see below).
Installation
If your Vim supports packages (echo has('packages')
prints 1
), I strongly
recommend that you use them. Just clone this repo inside pack/*/start
, e.g.,
cd ~/.vim
git clone https://github.com/lifepillar/pgsql.vim.git pack/bundle/start/pgsql
Otherwise, if you don't have a preferred installation method, I recommend
installing Pathogen, and then simply
copy and paste:
cd ~/.vim/bundle
git clone https://github.com/lifepillar/pgsql.vim.git
Usage
For thorough documentation, see :h pgsql.txt
.
Files with a .pgsql
suffix are highlighted out of the box. If you want to
highlight .sql
files using this plugin by default, add this to your .vimrc
(see :h ft_sql.txt
):
let g:sql_type_default = 'pgsql'
Alternatively, after loading a .sql
file use this command:
:SQLSetType pgsql.vim
To set the file type in new buffers use:
:let b:sql_type_override='pgsql' | set ft=sql
Code between $pgsql$
or $$
pairs is treated as PL/pgSQL and highlighted
accordingly:
You may set g:pgsql_pl
to a list of file types to be used in user-defined
- For example, after setting:
let g:pgsql_pl = ['python']
code between $python$
pairs will be highlighted as Python:
Hacking
The syntax file is generated automatically. If you want to hack it, editsrc/pgsql.sql
, then execute:
cd src
make install
This will update syntax/pgsql.vim
. Note that you will need a working local
PostgreSQL instance: make
will create a database called vim_pgsql_syntax
to
extract all the keywords. You may then execute make distclean
to drop the
database.
The script has been tested in macOS, but it should work on any *nix system.
Acknowledgments
This plugin was originally based on code from
space::tekk (and completely
rewritten).