*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 map assumes tables)
Stored Procedure List - <C-C>p
View List - <C-C>v
Column List - <C-C>c
Drilling In / Out - When viewing a popup window displaying the list
of tables, you can press <Right>, this will
replace the table currently highlighted with
the column list for that table.
- When viewing a popup window displaying the list
of columns, you can press <Left>, this will
replace the column list with the list of tables.
- This allows you to quickly drill down into a
table to view its columns and back again.
- <Right> and <Left> can also be chosen via
your |init.vim| >
let 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*
This tutorial is designed to take you through the common features of the SQL
completion plugin so that: >
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
Static features ~
To take you through the various lists, simply enter insert mode, hit:
<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.
When writing stored procedures using the "type" list is useful. It contains
a list of all the database supported types. This may or may not be true
depending on the syntax file you are using. The SQL Anywhere syntax file
(sqlanywhere.vim) has support for this: >
BEGIN
DECLARE customer_id <C-C>T <-- Choose a type from the list
Dynamic features ~
To take advantage of the dynamic features you must first install the
dbext.vim plugin (https://vim.sourceforge.net/script.php?script_id=356). It
also comes with a tutorial. From the SQL completion plugin's perspective,
the main feature dbext provides is a connection to a database. dbext
connection profiles are the most efficient