Home Explore Blog CI



neovim

4th chunk of `runtime/doc/ft_sql.txt`
ef980f229219f27ea99901f62ba5cb899cade57d114eea790000000100000fa1

------------------------------------------------------------------------------
2.3 SQL Dialect Default				*sql-type-default*

As mentioned earlier, the default syntax rules for Vim is based on Oracle
(PL/SQL).  You can override this default by placing one of the following in
your |init.vim|: >
    let g:sql_type_default = 'sqlanywhere'
    let g:sql_type_default = 'sqlinformix'
    let g:sql_type_default = 'mysql'

If you added the following to your |init.vim|: >
    let g:sql_type_default = 'sqlinformix'

The next time edit a SQL file the following scripts will be automatically
loaded by Vim: >
    ftplugin/sql.vim
    syntax/sqlinformix.vim
    indent/sql.vim
<
Notice indent/sqlinformix.sql was not loaded.  There is no indent file
for Informix, Vim loads the default files if the specified files does not
exist.


==============================================================================
3. Adding new SQL Dialects			*sql-adding-dialects*

If you begin working with a SQL dialect which does not have any customizations
available with the default Vim distribution you can check https://www.vim.org
to see if any customization currently exist.  If not, you can begin by cloning
an existing script.  Read |filetype-plugins| for more details.

To help identify these scripts, try to create the files with a "sql" prefix.
If you decide you wish to create customizations for the SQLite database, you
can create any of the following: >
    Unix
	~/.config/nvim/syntax/sqlite.vim
	~/.config/nvim/indent/sqlite.vim

No changes are necessary to the SQLSetType function.  It will automatically
pick up the new SQL files and load them when you issue the SQLSetType command.


==============================================================================
4. OMNI SQL Completion				*sql-completion*
						*omni-sql-completion*

Vim 7 includes a code completion interface and functions which allows plugin
developers to build in code completion for any language.  Vim 7 includes
code completion for the SQL language.

There are two modes to the SQL completion plugin, static and dynamic.  The
static mode populates the popups with the data generated from current syntax
highlight rules.  The dynamic mode populates the popups with data retrieved
directly from a database.  This includes, table lists, column lists,
procedures names and more.

------------------------------------------------------------------------------
4.1 Static Mode					*sql-completion-static*

The static popups created contain items defined by the active syntax rules
while editing a file with a filetype of SQL.  The plugin defines (by default)
various maps to help the user refine the list of items to be displayed.
The defaults static maps are: >
    imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O>
    imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
    imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O>
    imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O>
    imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O>
    imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O>

The use of "<C-C>" can be user chosen by using the following in your |init.vim|
as it may not work properly on all platforms: >
    let g:ftplugin_sql_omni_key = '<C-C>'
<
The static maps (which are based on the syntax highlight groups) follow this
format: >
    imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
    imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword\w*')<CR><C-X><C-O>

This command breaks down as: >
    imap		   - Create an insert map
    <buffer>		   - Only for this buffer
    <C-C>k		   - Your choice of key map
    <C-\><C-O>		   - Execute one command, return to Insert mode
    :call sqlcomplete#Map( - Allows the SQL completion plugin to perform some
			     housekeeping functions to allow it to

Title: Adding SQL Dialects and Static SQL Completion in Vim
Summary
This section explains how to add new SQL dialects to Vim, including creating syntax and indent files. It advises checking vim.org for existing customizations and suggests cloning existing scripts. It then introduces static SQL completion in Vim 7, which uses syntax highlighting to populate completion popups, and details the default keymaps for refining the displayed items.