Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
if elseif | elsif else [if] end if [while condition] loop leave break continue exit end loop for leave break continue exit end loop do statements doend case when when default end case merge when not matched when matched create[ or replace] procedure|function|event returns
]] move forward to the next 'begin' [[ move backwards to the previous 'begin' ][ move forward to the next 'end' [] move backwards to the previous 'end'
let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' .. \ ',schema,service,publication,database,datatype,domain' .. \ ',index,subscription,synchronization,view,variable'The following Normal mode and Visual mode maps have been created which use the above list:
]} move forward to the next 'create <object name>' [{ move backward to the previous 'create <object name>'Repeatedly pressing ]} will cycle through each of these create statements:
create table t1 ( ... ); create procedure p1 begin ... end; create index i1 on t1 (c1);The default setting for g:ftplugin_sql_objects is:
let g:ftplugin_sql_objects = 'function,procedure,event,' .. \ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' .. \ 'table,trigger' .. \ ',schema,service,publication,database,datatype,domain' .. \ ',index,subscription,synchronization,view,variable'The above will also handle these cases:
create table t1 ( ... ); create existing table t2 ( ... ); create global temporary table t3 ( ... );By default, the ftplugin only searches for CREATE statements. You can also override this via your init.vim with the following:
let g:ftplugin_sql_statements = 'create,alter'The filetype plugin defines three types of comments:
1. -- 2. // 3. /* * */The following Normal mode and Visual mode maps have been created to work with comments:
]" move forward to the beginning of a comment [" move forward to the end of a comment
\c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>This addresses the following code:
CREATE VARIABLE myVar1 INTEGER; CREATE PROCEDURE sp_test( IN myVar2 INTEGER, OUT myVar3 CHAR(30), INOUT myVar4 NUMERIC(20,0) ) BEGIN DECLARE myVar5 INTEGER; SELECT c1, c2, c3 INTO myVar2, myVar3, myVar4 FROM T1 WHERE c4 = myVar1; END;Place your cursor on "myVar1" on this line:
WHERE c4 = myVar1; ^Press any of the following keys:
[d [D [CTRL-D
SQLSetTypeExecuting this function without any parameters will set the indent and syntax scripts back to their defaults, see sql-type-default. You can use the
<Tab>
key to complete the optional parameter.:SQLSetType :SQLSetType sqloracle :SQLSetType sqlanywhere :SQLSetType sqlinformix :SQLSetType mysqlThe easiest approach is to the use
<Tab>
character which will first complete
the command name (SQLSetType), after a space and another <Tab>
, display a list
of available Vim script names::SQL<Tab><space><Tab>
SQLGetTypeThis will echo:
Current SQL dialect in use:sqlanywhere
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
Unix ~/.config/nvim/syntax/sqlite.vim ~/.config/nvim/indent/sqlite.vimNo 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.
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>'
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 be used in conjunction with other completion plugins. Indicate which item you want the SQL completion plugin to complete. In this case we are asking the plugin to display items from the syntax highlight group 'sqlKeyword'. You can view a list of highlight group names to choose from by executing the :syntax list command while editing a SQL file. 'sqlKeyword' - Display the items for the sqlKeyword highlight group 'sqlKeyword\w*' - A second option available with Vim 7.4 which uses a regular expression to determine which syntax groups to use )<CR> - Execute the :let command <C-X><C-O> - Trigger the standard omni completion key stroke. Passing in 'sqlKeyword' instructs the SQL completion plugin to populate the popup with items from the sqlKeyword highlight group. The plugin will also cache this result until Vim is restarted. The syntax list is retrieved using the syntaxcomplete plugin.Using the 'syntax' keyword is a special case. This instructs the syntaxcomplete plugin to retrieve all syntax items. So this will effectively work for any of Vim's SQL syntax files. At the time of writing this includes 10 different syntax files for the different dialects of SQL (see section 3 above, sql-dialects).
All - Contains the contents of all syntax highlight groups Statements - Select, Insert, Update, Delete, Create, Alter, ... Functions - Min, Max, Trim, Round, Date, ... Keywords - Index, Database, Having, Group, With Options - Isolation_level, On_error, Qualify_owners, Fire_triggers, ... Types - Integer, Char, Varchar, Date, DateTime, Timestamp, ...
Table List - All tables for all schema owners Procedure List - All stored procedures for all schema owners View List - All stored procedures for all schema owners Column List - For the selected table, the columns that are part of the tableTo enable the popup, while in INSERT mode, use the following key combinations for each group (where
<C-C>
means hold the CTRL key down while pressing
the space bar):
Table List - <C-C>
t
<C-X>
<C-O>
(the default map assumes tables)
Stored Procedure List - <C-C>
p
View List - <C-C>
v
Column List - <C-C>
c
<Right>
, this will
replace the table currently highlighted with
the column list for that table.
<Left>
, this will
replace the column list with the list of tables.
<Right>
and <Left>
can also be chosen via
your init.vimlet g:ftplugin_sql_omni_key_right = '<Right>' let g:ftplugin_sql_omni_key_left = '<Left>'The SQL completion plugin caches various lists that are displayed in the popup window. This makes the re-displaying of these lists very fast. If new tables or columns are added to the database it may become necessary to clear the plugins cache. The default map for this is:
imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O>------------------------------------------------------------------------------ 4.3 SQL Tutorial sql-completion-tutorial
a) You gain familiarity with the plugin b) You are introduced to some of the more common features c) Show how to customize it to your preferences d) Demonstrate "Best of Use" of the plugin (easiest way to configure).First, create a new buffer:
:e tutorial.sql
<C-C>
s (show SQL statements)
At this point, you can page down through the list until you find "select".
If you are familiar with the item you are looking for, for example you know
the statement begins with the letter "s". You can type ahead (without the
quotes) "se" then press:
<C-Space>
t
Assuming "select" is highlighted in the popup list press <Enter>
to choose
the entry. Now type:
* fr<C-C>a (show all syntax items)
choose "from" from the popup list.BEGIN DECLARE customer_id <C-C>T <-- Choose a type from the list
<C-C>
t to
display a list of tables. There is a delay while dbext is creating the table
list. After the list is displayed press <C-W>
. This will remove both the
popup window and the table name already chosen when the list became active.<C-C>
t to display a list of tables from within the database you
have connected via the dbext plugin.
NOTE: All of the SQL completion popups support typing a prefix before pressing
the key map. This will limit the contents of the popup window to just items
beginning with those characters.<C-C>
c.<Right>
to trigger a column list while
the popup window is active.<C-C>
t again to display the list of tables.
<Right>
,
this will replace the list of tables, with a list of columns for the
table highlighted (after the same short delay).
<Left>
, this will again replace the column list with the
list of tables. This allows you to drill into tables and column lists
very quickly.
<Right>
again while the same table is highlighted. You will
notice there is no delay since the column list has been cached. If you
change the schema of a cached table you can press <C-C>
R, which
clears the SQL completion cache.
<Right>
and <Left>
have been designed to work while the
completion window is active. If the completion popup window is
not active, a normal <Right>
or <Left>
will be executed.
One column at a time:
<C-C>
t to display a list of tables.
2. Choose a table from the list.
3. Press <Right>
to display a list of columns.
4. Choose the column from the list and press enter.
5. Enter a "," and press <C-C>
c. Generating a column list
generally requires having the cursor on a table name. The plugin
uses this name to determine what table to retrieve the column list.
In this step, since we are pressing <C-C>
c without the cursor
on a table name the column list displayed will be for the previous
table. Choose a different column and move on.
6. Repeat step 5 as often as necessary.All columns for a table:
<C-C>
t to display a list of tables.
2. Highlight the table you need the column list for.
3. Press <Enter>
to choose the table from the list.
4. Press <C-C>
l to request a comma-separated list of all columns
for this table.
5. Based on the table name chosen in step 3, the plugin attempts to
decide on a reasonable table alias. You are then prompted to
either accept of change the alias. Press OK.
6. The table name is replaced with the column list of the table is
replaced with the comma separate list of columns with the alias
prepended to each of the columns.
7. Step 3 and 4 can be replaced by pressing <C-C>
L, which has
a <C-Y>
embedded in the map to choose the currently highlighted
table in the list.select * from customer c, contact cn, department as dp, employee e, site_options so where c.In INSERT mode after typing the final "c." which is an alias for the "customer" table, you can press either
<C-C>
c or <C-X>
<C-O>
. This will
popup a list of columns for the customer table. It does this by looking back
to the beginning of the select statement and finding a list of the tables
specified in the FROM clause. In this case it notes that in the string
"customer c", "c" is an alias for the customer table. The optional "AS"
keyword is also supported, "customer AS c".<C-C>
p, will display a list of stored
procedures stored within the database.<C-C>
v, will display a list of views in the
database.omni_sql_no_default_maps
<C-C>
l. When generating
a column list, an alias can be prepended to the beginning of each
column, for example: e.emp_id, e.emp_name. This option has three
settings:n - do not use an alias d - use the default (calculated) alias a - ask to confirm the alias name
MY_TABLE_NAME --> MTN my_table_name --> mtn My_table_NAME --> MtN
MyTableName --> MTN
mytablename --> m MYTABLENAME --> M omni_sql_ignorecase
omni_sql_include_owner
omni_sql_precache_syntax_groups
<C-C>a
<C-C>k
<C-C>f
<C-C>o
<C-C>T
<C-C>s
<C-C>t
<C-C>p
<C-C>v
<C-C>c
<C-C>l
<C-C>L
<Right>
<Right>
is not recognized on most Unix
systems, so this maps is only created on the Windows platform.
If you would like the same feature on Unix, choose a different key
and make the same map in your vimrc.<Left>
<Left>
is not recognized on most Unix systems, so this maps is
only created on the Windows platform. If you would like the same
feature on Unix, choose a different key and make the same map in
your vimrc.<C-C>R
let g:omni_sql_no_default_maps = 1Do not edit ftplugin/sql.vim directly! If you change this file your changes will be over written on future updates. Vim has a special directory structure which allows you to make customizations without changing the files that are included with the Vim distribution. If you wish to customize the maps create an after/ftplugin/sql.vim (see after-directory) and place the same maps from the ftplugin/sql.vim in it using your own key strokes.
<C-C>
was
chosen since it will work on both Windows and unix platforms. On the windows
platform you can also use <C-Space>
or ALT keys.1. :e test.pl 2. :set filetype=sql 3. :set ft=perl
<C-X>
<C-O>
will display the omni popup containing
the syntax items for Perl.<C-C>
, the maps will toggle the 'omnifunc' when in use. So you
can use <C-X>
<C-O>
to continue using the completion for Perl (using the syntax
completion plugin) and <C-C>
to use the SQL completion features.