Home Explore Blog CI



neovim

5th chunk of `runtime/doc/ft_sql.txt`
4f9ae6c6c7e7dc1b403f6e9be1c8683b30bf77a47fa201570000000100000fa0
 <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 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|).

Here are some examples of the entries which are pulled from the syntax files: >
     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, ...


------------------------------------------------------------------------------
4.2 Dynamic Mode				*sql-completion-dynamic*

Dynamic mode populates the popups with data directly from a database.  In
order for the dynamic feature to be enabled you must have the dbext.vim
plugin installed, (https://vim.sourceforge.net/script.php?script_id=356).

Dynamic mode is used by several features of the SQL completion plugin.
After installing the dbext plugin see the dbext-tutorial for additional
configuration and usage.  The dbext plugin allows the SQL completion plugin
to display a list of tables, procedures, views and columns. >
     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 table

To 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

Title: Static and Dynamic SQL Completion Details in Vim
Summary
This section details the static SQL completion feature in Vim, explaining the keymaps used to refine the list of completion items based on syntax highlight groups (like sqlKeyword, sqlOption, sqlType, sqlStatement). It describes how the 'sqlcomplete#Map' function works in conjunction with other completion plugins, how to customize the keybindings. It then introduces dynamic SQL completion, which requires the dbext.vim plugin and retrieves data directly from a database, providing lists of tables, procedures, views, and columns.