Coder Social home page Coder Social logo

pgsql.vim's Introduction

Vim PostgreSQL syntax plugin

pgsql syntax highlighting

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.,

mkdir -p ~/.vim/pack/plugins/start
git clone https://github.com/lifepillar/pgsql.vim.git ~/.vim/pack/plugins/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:

PL/pgSQL snippet

You may set g:pgsql_pl to a list of file types to be used in user-defined functions. For example, after setting:

let g:pgsql_pl = ['python']

code between $python$ pairs will be highlighted as Python:

PL/Pythonu snippet

Hacking

The syntax file is generated automatically. If you want to hack it, edit src/pgsql.sql, then execute:

cd ./src
DBUSER=<user> DBHOST=<hostname> make install

When DBUSER is omitted, postgres is assumed. When DBHOST is omitted, 127.0.0.1 is assumed.

The specified user must be a superuser, because the script will create a database called vim_pgsql_syntax and a few extensions that require admin privileges. It will then proceed to extract all the keywords. Feel free to browse the source scripts to see exactly what they do.

The above command will update syntax/pgsql.vim. Use make distclean to drop the database (or drop it manually).

The script has been tested in macOS, but it should work on other systems as well.

Acknowledgments

This plugin was originally based on code from space::tekk (and completely rewritten).

pgsql.vim's People

Contributors

lifepillar avatar spacetekk avatar mgedmin avatar stephenwall avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.