xref: /vim-8.2.3635/runtime/doc/ft_sql.txt (revision d2ea7cf1)
198056533SBram Moolenaar*ft_sql.txt*	For Vim version 8.2.  Last change: 2019 Dec 07
2a7241f5fSBram Moolenaar
3a7241f5fSBram Moolenaarby David Fishburn
4a7241f5fSBram Moolenaar
5a7241f5fSBram MoolenaarThis is a filetype plugin to work with SQL files.
6a7241f5fSBram Moolenaar
7a7241f5fSBram MoolenaarThe Structured Query Language (SQL) is a standard which specifies statements
8a7241f5fSBram Moolenaarthat allow a user to interact with a relational database.  Vim includes
9a7241f5fSBram Moolenaarfeatures for navigation, indentation and syntax highlighting.
10a7241f5fSBram Moolenaar
11a7241f5fSBram Moolenaar1. Navigation					|sql-navigation|
12a7241f5fSBram Moolenaar    1.1 Matchit					|sql-matchit|
13a7241f5fSBram Moolenaar    1.2 Text Object Motions			|sql-object-motions|
14a7241f5fSBram Moolenaar    1.3 Predefined Object Motions		|sql-predefined-objects|
15a7241f5fSBram Moolenaar    1.4 Macros					|sql-macros|
16a7241f5fSBram Moolenaar2. SQL Dialects					|sql-dialects|
17a7241f5fSBram Moolenaar    2.1 SQLSetType				|SQLSetType|
188f3f58f2SBram Moolenaar    2.2 SQLGetType				|SQLGetType|
198f3f58f2SBram Moolenaar    2.3 SQL Dialect Default			|sql-type-default|
20a7241f5fSBram Moolenaar3. Adding new SQL Dialects			|sql-adding-dialects|
21a7241f5fSBram Moolenaar4. OMNI SQL Completion				|sql-completion|
22a7241f5fSBram Moolenaar    4.1 Static mode				|sql-completion-static|
23a7241f5fSBram Moolenaar    4.2 Dynamic mode				|sql-completion-dynamic|
24a7241f5fSBram Moolenaar    4.3 Tutorial				|sql-completion-tutorial|
25a7241f5fSBram Moolenaar	4.3.1 Complete Tables			|sql-completion-tables|
26a7241f5fSBram Moolenaar	4.3.2 Complete Columns			|sql-completion-columns|
27a7241f5fSBram Moolenaar	4.3.3 Complete Procedures		|sql-completion-procedures|
28a7241f5fSBram Moolenaar	4.3.4 Complete Views			|sql-completion-views|
29a7241f5fSBram Moolenaar    4.4 Completion Customization		|sql-completion-customization|
30a7241f5fSBram Moolenaar    4.5 SQL Maps				|sql-completion-maps|
31a7241f5fSBram Moolenaar    4.6 Using with other filetypes		|sql-completion-filetypes|
32a7241f5fSBram Moolenaar
33a7241f5fSBram Moolenaar==============================================================================
34a7241f5fSBram Moolenaar1. Navigation					*sql-navigation*
35a7241f5fSBram Moolenaar
36a7241f5fSBram MoolenaarThe SQL ftplugin provides a number of options to assist with file
37a7241f5fSBram Moolenaarnavigation.
38a7241f5fSBram Moolenaar
39a7241f5fSBram Moolenaar
40a7241f5fSBram Moolenaar1.1 Matchit					*sql-matchit*
41a7241f5fSBram Moolenaar-----------
42a7241f5fSBram MoolenaarThe matchit plugin (http://www.vim.org/scripts/script.php?script_id=39)
43a7241f5fSBram Moolenaarprovides many additional features and can be customized for different
44a7241f5fSBram Moolenaarlanguages.  The matchit plugin is configured by defining a local
45a7241f5fSBram Moolenaarbuffer variable, b:match_words.  Pressing the % key while on various
46a7241f5fSBram Moolenaarkeywords will move the cursor to its match.  For example, if the cursor
47a7241f5fSBram Moolenaaris on an "if", pressing % will cycle between the "else", "elseif" and
48a7241f5fSBram Moolenaar"end if" keywords.
49a7241f5fSBram Moolenaar
50a7241f5fSBram MoolenaarThe following keywords are supported: >
51a7241f5fSBram Moolenaar    if
52a7241f5fSBram Moolenaar    elseif | elsif
53a7241f5fSBram Moolenaar    else [if]
54a7241f5fSBram Moolenaar    end if
55a7241f5fSBram Moolenaar
56a7241f5fSBram Moolenaar    [while condition] loop
57a7241f5fSBram Moolenaar	leave
58a7241f5fSBram Moolenaar	break
59a7241f5fSBram Moolenaar	continue
60a7241f5fSBram Moolenaar	exit
61a7241f5fSBram Moolenaar    end loop
62a7241f5fSBram Moolenaar
63a7241f5fSBram Moolenaar    for
64a7241f5fSBram Moolenaar	leave
65a7241f5fSBram Moolenaar	break
66a7241f5fSBram Moolenaar	continue
67a7241f5fSBram Moolenaar	exit
68a7241f5fSBram Moolenaar    end loop
69a7241f5fSBram Moolenaar
70a7241f5fSBram Moolenaar    do
71a7241f5fSBram Moolenaar	statements
72a7241f5fSBram Moolenaar    doend
73a7241f5fSBram Moolenaar
74a7241f5fSBram Moolenaar    case
75a7241f5fSBram Moolenaar    when
76a7241f5fSBram Moolenaar    when
77a7241f5fSBram Moolenaar    default
78a7241f5fSBram Moolenaar    end case
79a7241f5fSBram Moolenaar
80a7241f5fSBram Moolenaar    merge
81a7241f5fSBram Moolenaar    when not matched
82a7241f5fSBram Moolenaar    when matched
83a7241f5fSBram Moolenaar
84a7241f5fSBram Moolenaar    create[ or replace] procedure|function|event
85a7241f5fSBram Moolenaar    returns
86a7241f5fSBram Moolenaar
87a7241f5fSBram Moolenaar
88a7241f5fSBram Moolenaar1.2 Text Object Motions				*sql-object-motions*
89a7241f5fSBram Moolenaar-----------------------
90a7241f5fSBram MoolenaarVim has a number of predefined keys for working with text |object-motions|.
91a7241f5fSBram MoolenaarThis filetype plugin attempts to translate these keys to maps which make sense
92a7241f5fSBram Moolenaarfor the SQL language.
93a7241f5fSBram Moolenaar
94a7241f5fSBram MoolenaarThe following |Normal| mode and |Visual| mode maps exist (when you edit a SQL
95a7241f5fSBram Moolenaarfile): >
96a7241f5fSBram Moolenaar    ]]		    move forward to the next 'begin'
97a7241f5fSBram Moolenaar    [[		    move backwards to the previous 'begin'
98a7241f5fSBram Moolenaar    ][		    move forward to the next 'end'
99a7241f5fSBram Moolenaar    []		    move backwards to the previous 'end'
100a7241f5fSBram Moolenaar
101a7241f5fSBram Moolenaar
102a7241f5fSBram Moolenaar1.3 Predefined Object Motions			*sql-predefined-objects*
103a7241f5fSBram Moolenaar-----------------------------
104a7241f5fSBram MoolenaarMost relational databases support various standard features, tables, indices,
105a7241f5fSBram Moolenaartriggers and stored procedures.  Each vendor also has a variety of proprietary
106a7241f5fSBram Moolenaarobjects.  The next set of maps have been created to help move between these
107a7241f5fSBram Moolenaarobjects.  Depends on which database vendor you are using, the list of objects
108a7241f5fSBram Moolenaarmust be configurable.  The filetype plugin attempts to define many of the
109a7241f5fSBram Moolenaarstandard objects, plus many additional ones.  In order to make this as
110a7241f5fSBram Moolenaarflexible as possible, you can override the list of objects from within your
111a7241f5fSBram Moolenaar|vimrc| with the following: >
112a7241f5fSBram Moolenaar    let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' .
113a7241f5fSBram Moolenaar		\ ',schema,service,publication,database,datatype,domain' .
114a7241f5fSBram Moolenaar		\ ',index,subscription,synchronization,view,variable'
115a7241f5fSBram Moolenaar
116a7241f5fSBram MoolenaarThe following |Normal| mode and |Visual| mode maps have been created which use
117a7241f5fSBram Moolenaarthe above list: >
118a7241f5fSBram Moolenaar    ]}		    move forward to the next 'create <object name>'
119a7241f5fSBram Moolenaar    [{		    move backward to the previous 'create <object name>'
120a7241f5fSBram Moolenaar
121a7241f5fSBram MoolenaarRepeatedly pressing ]} will cycle through each of these create statements: >
122a7241f5fSBram Moolenaar    create table t1 (
123a7241f5fSBram Moolenaar	...
124a7241f5fSBram Moolenaar    );
125a7241f5fSBram Moolenaar
126a7241f5fSBram Moolenaar    create procedure p1
127a7241f5fSBram Moolenaar    begin
128a7241f5fSBram Moolenaar	...
129a7241f5fSBram Moolenaar    end;
130a7241f5fSBram Moolenaar
131a7241f5fSBram Moolenaar    create index i1 on t1 (c1);
132a7241f5fSBram Moolenaar
133a7241f5fSBram MoolenaarThe default setting for g:ftplugin_sql_objects is: >
134a7241f5fSBram Moolenaar    let g:ftplugin_sql_objects = 'function,procedure,event,' .
135a7241f5fSBram Moolenaar		\ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' .
136a7241f5fSBram Moolenaar		\ 'table,trigger' .
137a7241f5fSBram Moolenaar		\ ',schema,service,publication,database,datatype,domain' .
138a7241f5fSBram Moolenaar		\ ',index,subscription,synchronization,view,variable'
139a7241f5fSBram Moolenaar
140a7241f5fSBram MoolenaarThe above will also handle these cases: >
141a7241f5fSBram Moolenaar    create table t1 (
142a7241f5fSBram Moolenaar	...
143a7241f5fSBram Moolenaar    );
144a7241f5fSBram Moolenaar    create existing table t2 (
145a7241f5fSBram Moolenaar	...
146a7241f5fSBram Moolenaar    );
147a7241f5fSBram Moolenaar    create global temporary table t3 (
148a7241f5fSBram Moolenaar	...
149a7241f5fSBram Moolenaar    );
150a7241f5fSBram Moolenaar
151a7241f5fSBram MoolenaarBy default, the ftplugin only searches for CREATE statements.  You can also
152a7241f5fSBram Moolenaaroverride this via your |vimrc| with the following: >
153a7241f5fSBram Moolenaar    let g:ftplugin_sql_statements = 'create,alter'
154a7241f5fSBram Moolenaar
155a7241f5fSBram MoolenaarThe filetype plugin defines three types of comments: >
156a7241f5fSBram Moolenaar    1.  --
157a7241f5fSBram Moolenaar    2.  //
158a7241f5fSBram Moolenaar    3.  /*
159a7241f5fSBram Moolenaar	 *
160a7241f5fSBram Moolenaar	 */
161a7241f5fSBram Moolenaar
162a7241f5fSBram MoolenaarThe following |Normal| mode and |Visual| mode maps have been created to work
163a7241f5fSBram Moolenaarwith comments: >
164a7241f5fSBram Moolenaar    ]"		    move forward to the beginning of a comment
165a7241f5fSBram Moolenaar    ["		    move forward to the end of a comment
166a7241f5fSBram Moolenaar
167a7241f5fSBram Moolenaar
168a7241f5fSBram Moolenaar
169a7241f5fSBram Moolenaar1.4 Macros					   *sql-macros*
170a7241f5fSBram Moolenaar----------
171a7241f5fSBram MoolenaarVim's feature to find macro definitions, |'define'|, is supported using this
172a7241f5fSBram Moolenaarregular expression: >
173a7241f5fSBram Moolenaar    \c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>
174a7241f5fSBram Moolenaar
175a7241f5fSBram MoolenaarThis addresses the following code: >
176a7241f5fSBram Moolenaar    CREATE VARIABLE myVar1 INTEGER;
177a7241f5fSBram Moolenaar
178a7241f5fSBram Moolenaar    CREATE PROCEDURE sp_test(
179a7241f5fSBram Moolenaar	IN myVar2 INTEGER,
180a7241f5fSBram Moolenaar	OUT myVar3 CHAR(30),
181a7241f5fSBram Moolenaar	INOUT myVar4 NUMERIC(20,0)
182a7241f5fSBram Moolenaar    )
183a7241f5fSBram Moolenaar    BEGIN
184a7241f5fSBram Moolenaar	DECLARE myVar5 INTEGER;
185a7241f5fSBram Moolenaar
186a7241f5fSBram Moolenaar	SELECT c1, c2, c3
187a7241f5fSBram Moolenaar	  INTO myVar2, myVar3, myVar4
188a7241f5fSBram Moolenaar	  FROM T1
189a7241f5fSBram Moolenaar	 WHERE c4 = myVar1;
190a7241f5fSBram Moolenaar    END;
191a7241f5fSBram Moolenaar
192a7241f5fSBram MoolenaarPlace your cursor on "myVar1" on this line: >
193a7241f5fSBram Moolenaar	 WHERE c4 = myVar1;
194a7241f5fSBram Moolenaar		     ^
195a7241f5fSBram Moolenaar
196a7241f5fSBram MoolenaarPress any of the following keys: >
197a7241f5fSBram Moolenaar    [d
198a7241f5fSBram Moolenaar    [D
199a7241f5fSBram Moolenaar    [CTRL-D
200a7241f5fSBram Moolenaar
201a7241f5fSBram Moolenaar
202a7241f5fSBram Moolenaar==============================================================================
203a7241f5fSBram Moolenaar2. SQL Dialects					*sql-dialects* *sql-types*
204a7241f5fSBram Moolenaar						*sybase* *TSQL* *Transact-SQL*
205a7241f5fSBram Moolenaar						*sqlanywhere*
206a7241f5fSBram Moolenaar						*oracle* *plsql* *sqlj*
207a7241f5fSBram Moolenaar						*sqlserver*
208fcb7ab61SBram Moolenaar						*mysql* *postgresql* *psql*
209a7241f5fSBram Moolenaar						*informix*
210a7241f5fSBram Moolenaar
211a7241f5fSBram MoolenaarAll relational databases support SQL.  There is a portion of SQL that is
212a7241f5fSBram Moolenaarportable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a
213a7241f5fSBram Moolenaargreat deal of vendor specific extensions to SQL.  Oracle supports the
214a7241f5fSBram Moolenaar"CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE
215a7241f5fSBram Moolenaarstatement and the procedural language (for stored procedures and triggers).
216a7241f5fSBram Moolenaar
217a7241f5fSBram MoolenaarThe default Vim distribution ships with syntax highlighting based on Oracle's
218a7241f5fSBram MoolenaarPL/SQL.  The default SQL indent script works for Oracle and SQL Anywhere.
219a7241f5fSBram MoolenaarThe default filetype plugin works for all vendors and should remain vendor
220a7241f5fSBram Moolenaarneutral, but extendable.
221a7241f5fSBram Moolenaar
222a7241f5fSBram MoolenaarVim currently has support for a variety of different vendors, currently this
223a7241f5fSBram Moolenaaris via syntax scripts. Unfortunately, to flip between different syntax rules
224a7241f5fSBram Moolenaaryou must either create:
225a7241f5fSBram Moolenaar    1.  New filetypes
226a7241f5fSBram Moolenaar    2.  Custom autocmds
227a7241f5fSBram Moolenaar    3.  Manual steps / commands
228a7241f5fSBram Moolenaar
229a7241f5fSBram MoolenaarThe majority of people work with only one vendor's database product, it would
230a7241f5fSBram Moolenaarbe nice to specify a default in your |vimrc|.
231a7241f5fSBram Moolenaar
232a7241f5fSBram Moolenaar
233a7241f5fSBram Moolenaar2.1 SQLSetType					*sqlsettype* *SQLSetType*
234a7241f5fSBram Moolenaar--------------
2358f3f58f2SBram MoolenaarFor the people that work with many different databases, it is nice to be
236a7241f5fSBram Moolenaarable to flip between the various vendors rules (indent, syntax) on a per
237a7241f5fSBram Moolenaarbuffer basis, at any time.  The ftplugin/sql.vim file defines this function: >
238a7241f5fSBram Moolenaar    SQLSetType
239a7241f5fSBram Moolenaar
240a7241f5fSBram MoolenaarExecuting this function without any parameters will set the indent and syntax
241a7241f5fSBram Moolenaarscripts back to their defaults, see |sql-type-default|.  If you have turned
242a7241f5fSBram Moolenaaroff Vi's compatibility mode, |'compatible'|, you can use the <Tab> key to
243a7241f5fSBram Moolenaarcomplete the optional parameter.
244a7241f5fSBram Moolenaar
245a7241f5fSBram MoolenaarAfter typing the function name and a space, you can use the completion to
246a7241f5fSBram Moolenaarsupply a parameter.  The function takes the name of the Vim script you want to
247a7241f5fSBram Moolenaarsource.  Using the |cmdline-completion| feature, the SQLSetType function will
248a7241f5fSBram Moolenaarsearch the |'runtimepath'| for all Vim scripts with a name containing 'sql'.
249a7241f5fSBram MoolenaarThis takes the guess work out of the spelling of the names.  The following are
250a7241f5fSBram Moolenaarexamples: >
251a7241f5fSBram Moolenaar    :SQLSetType
252a7241f5fSBram Moolenaar    :SQLSetType sqloracle
253a7241f5fSBram Moolenaar    :SQLSetType sqlanywhere
254a7241f5fSBram Moolenaar    :SQLSetType sqlinformix
255a7241f5fSBram Moolenaar    :SQLSetType mysql
256a7241f5fSBram Moolenaar
257a7241f5fSBram MoolenaarThe easiest approach is to the use <Tab> character which will first complete
258a7241f5fSBram Moolenaarthe command name (SQLSetType), after a space and another <Tab>, display a list
259a7241f5fSBram Moolenaarof available Vim script names: >
260a7241f5fSBram Moolenaar    :SQL<Tab><space><Tab>
261a7241f5fSBram Moolenaar
262a7241f5fSBram Moolenaar
2638f3f58f2SBram Moolenaar2.2 SQLGetType					*sqlgettype* *SQLGetType*
2648f3f58f2SBram Moolenaar--------------
2658f3f58f2SBram MoolenaarAt anytime you can determine which SQL dialect you are using by calling the
2668f3f58f2SBram MoolenaarSQLGetType command.  The ftplugin/sql.vim file defines this function: >
2678f3f58f2SBram Moolenaar    SQLGetType
2688f3f58f2SBram Moolenaar
2698f3f58f2SBram MoolenaarThis will echo: >
2708f3f58f2SBram Moolenaar    Current SQL dialect in use:sqlanywhere
2718f3f58f2SBram Moolenaar
2728f3f58f2SBram Moolenaar
2738f3f58f2SBram Moolenaar2.3 SQL Dialect Default				*sql-type-default*
274a7241f5fSBram Moolenaar-----------------------
275a7241f5fSBram MoolenaarAs mentioned earlier, the default syntax rules for Vim is based on Oracle
276a7241f5fSBram Moolenaar(PL/SQL).  You can override this default by placing one of the following in
277a7241f5fSBram Moolenaaryour |vimrc|: >
278a7241f5fSBram Moolenaar    let g:sql_type_default = 'sqlanywhere'
279a7241f5fSBram Moolenaar    let g:sql_type_default = 'sqlinformix'
280a7241f5fSBram Moolenaar    let g:sql_type_default = 'mysql'
281a7241f5fSBram Moolenaar
282a7241f5fSBram MoolenaarIf you added the following to your |vimrc|: >
283a7241f5fSBram Moolenaar    let g:sql_type_default = 'sqlinformix'
284a7241f5fSBram Moolenaar
285a7241f5fSBram MoolenaarThe next time edit a SQL file the following scripts will be automatically
286a7241f5fSBram Moolenaarloaded by Vim: >
287a7241f5fSBram Moolenaar    ftplugin/sql.vim
288a7241f5fSBram Moolenaar    syntax/sqlinformix.vim
289a7241f5fSBram Moolenaar    indent/sql.vim
290a7241f5fSBram Moolenaar>
291a7241f5fSBram MoolenaarNotice indent/sqlinformix.sql was not loaded.  There is no indent file
292a7241f5fSBram Moolenaarfor Informix, Vim loads the default files if the specified files does not
293a7241f5fSBram Moolenaarexist.
294a7241f5fSBram Moolenaar
295a7241f5fSBram Moolenaar
296a7241f5fSBram Moolenaar==============================================================================
297a7241f5fSBram Moolenaar3. Adding new SQL Dialects			*sql-adding-dialects*
298a7241f5fSBram Moolenaar
299a7241f5fSBram MoolenaarIf you begin working with a SQL dialect which does not have any customizations
300a7241f5fSBram Moolenaaravailable with the default Vim distribution you can check http://www.vim.org
301a7241f5fSBram Moolenaarto see if any customization currently exist.  If not, you can begin by cloning
302a7241f5fSBram Moolenaaran existing script.  Read |filetype-plugins| for more details.
303a7241f5fSBram Moolenaar
304a7241f5fSBram MoolenaarTo help identify these scripts, try to create the files with a "sql" prefix.
305a7241f5fSBram MoolenaarIf you decide you wish to create customizations for the SQLite database, you
306a7241f5fSBram Moolenaarcan create any of the following: >
307a7241f5fSBram Moolenaar    Unix
308a7241f5fSBram Moolenaar	~/.vim/syntax/sqlite.vim
309a7241f5fSBram Moolenaar	~/.vim/indent/sqlite.vim
310a7241f5fSBram Moolenaar    Windows
311a7241f5fSBram Moolenaar	$VIM/vimfiles/syntax/sqlite.vim
312a7241f5fSBram Moolenaar	$VIM/vimfiles/indent/sqlite.vim
313a7241f5fSBram Moolenaar
314a7241f5fSBram MoolenaarNo changes are necessary to the SQLSetType function.  It will automatically
315a7241f5fSBram Moolenaarpick up the new SQL files and load them when you issue the SQLSetType command.
316a7241f5fSBram Moolenaar
317a7241f5fSBram Moolenaar
318a7241f5fSBram Moolenaar==============================================================================
319a7241f5fSBram Moolenaar4. OMNI SQL Completion				*sql-completion*
320a7241f5fSBram Moolenaar						*omni-sql-completion*
321a7241f5fSBram Moolenaar
322a7241f5fSBram MoolenaarVim 7 includes a code completion interface and functions which allows plugin
323a7241f5fSBram Moolenaardevelopers to build in code completion for any language.  Vim 7 includes
324a7241f5fSBram Moolenaarcode completion for the SQL language.
325a7241f5fSBram Moolenaar
326a7241f5fSBram MoolenaarThere are two modes to the SQL completion plugin, static and dynamic.  The
327a7241f5fSBram Moolenaarstatic mode populates the popups with the data generated from current syntax
328a7241f5fSBram Moolenaarhighlight rules.  The dynamic mode populates the popups with data retrieved
329a7241f5fSBram Moolenaardirectly from a database.  This includes, table lists, column lists,
330a7241f5fSBram Moolenaarprocedures names and more.
331a7241f5fSBram Moolenaar
332a7241f5fSBram Moolenaar4.1 Static Mode					*sql-completion-static*
333a7241f5fSBram Moolenaar---------------
334a7241f5fSBram MoolenaarThe static popups created contain items defined by the active syntax rules
335a7241f5fSBram Moolenaarwhile editing a file with a filetype of SQL.  The plugin defines (by default)
336a7241f5fSBram Moolenaarvarious maps to help the user refine the list of items to be displayed.
337a7241f5fSBram MoolenaarThe defaults static maps are: >
338a7241f5fSBram Moolenaar    imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O>
339a7241f5fSBram Moolenaar    imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
340a7241f5fSBram Moolenaar    imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O>
341a7241f5fSBram Moolenaar    imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O>
342a7241f5fSBram Moolenaar    imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O>
343a7241f5fSBram Moolenaar    imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O>
344a7241f5fSBram Moolenaar
345664f3cf3SBram MoolenaarThe use of "<C-C>" can be user chosen by using the following in your |.vimrc|
346664f3cf3SBram Moolenaaras it may not work properly on all platforms: >
3478f3f58f2SBram Moolenaar    let g:ftplugin_sql_omni_key = '<C-C>'
3488f3f58f2SBram Moolenaar>
349a7241f5fSBram MoolenaarThe static maps (which are based on the syntax highlight groups) follow this
350a7241f5fSBram Moolenaarformat: >
351a7241f5fSBram Moolenaar    imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
352ad3b366cSBram Moolenaar    imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword\w*')<CR><C-X><C-O>
353a7241f5fSBram Moolenaar
354a7241f5fSBram MoolenaarThis command breaks down as: >
355a7241f5fSBram Moolenaar    imap		   - Create an insert map
356a7241f5fSBram Moolenaar    <buffer>		   - Only for this buffer
357a7241f5fSBram Moolenaar    <C-C>k		   - Your choice of key map
358a7241f5fSBram Moolenaar    <C-\><C-O>		   - Execute one command, return to Insert mode
359a7241f5fSBram Moolenaar    :call sqlcomplete#Map( - Allows the SQL completion plugin to perform some
360a7241f5fSBram Moolenaar			     housekeeping functions to allow it to be used in
361a7241f5fSBram Moolenaar			     conjunction with other completion plugins.
362a7241f5fSBram Moolenaar			     Indicate which item you want the SQL completion
363a7241f5fSBram Moolenaar			     plugin to complete.
364a7241f5fSBram Moolenaar			     In this case we are asking the plugin to display
365a7241f5fSBram Moolenaar			     items from the syntax highlight group
366a7241f5fSBram Moolenaar			     'sqlKeyword'.
367a7241f5fSBram Moolenaar			     You can view a list of highlight group names to
368a7241f5fSBram Moolenaar			     choose from by executing the
369a7241f5fSBram Moolenaar				 :syntax list
370a7241f5fSBram Moolenaar			     command while editing a SQL file.
371a7241f5fSBram Moolenaar    'sqlKeyword'	   - Display the items for the sqlKeyword highlight
372a7241f5fSBram Moolenaar			     group
373ad3b366cSBram Moolenaar    'sqlKeyword\w*'	   - A second option available with Vim 7.4 which
374ad3b366cSBram Moolenaar                             uses a regular expression to determine which
375ad3b366cSBram Moolenaar			     syntax groups to use
376a7241f5fSBram Moolenaar    )<CR>		   - Execute the :let command
377a7241f5fSBram Moolenaar    <C-X><C-O>		   - Trigger the standard omni completion key stroke.
378a7241f5fSBram Moolenaar			     Passing in 'sqlKeyword' instructs the SQL
379a7241f5fSBram Moolenaar			     completion plugin to populate the popup with
380a7241f5fSBram Moolenaar			     items from the sqlKeyword highlight group.  The
381a7241f5fSBram Moolenaar			     plugin will also cache this result until Vim is
382a7241f5fSBram Moolenaar			     restarted.  The syntax list is retrieved using
383a7241f5fSBram Moolenaar			     the syntaxcomplete plugin.
384a7241f5fSBram Moolenaar
385a7241f5fSBram MoolenaarUsing the 'syntax' keyword is a special case.  This instructs the
386a7241f5fSBram Moolenaarsyntaxcomplete plugin to retrieve all syntax items.  So this will effectively
387a7241f5fSBram Moolenaarwork for any of Vim's SQL syntax files.  At the time of writing this includes
388a7241f5fSBram Moolenaar10 different syntax files for the different dialects of SQL (see section 3
389a7241f5fSBram Moolenaarabove, |sql-dialects|).
390a7241f5fSBram Moolenaar
391a7241f5fSBram MoolenaarHere are some examples of the entries which are pulled from the syntax files: >
392a7241f5fSBram Moolenaar     All
393a7241f5fSBram Moolenaar	 - Contains the contents of all syntax highlight groups
394a7241f5fSBram Moolenaar     Statements
395a7241f5fSBram Moolenaar	 - Select, Insert, Update, Delete, Create, Alter, ...
396a7241f5fSBram Moolenaar     Functions
397a7241f5fSBram Moolenaar	 - Min, Max, Trim, Round, Date, ...
398a7241f5fSBram Moolenaar     Keywords
399a7241f5fSBram Moolenaar	 - Index, Database, Having, Group, With
400a7241f5fSBram Moolenaar     Options
401a7241f5fSBram Moolenaar	 - Isolation_level, On_error, Qualify_owners, Fire_triggers, ...
402a7241f5fSBram Moolenaar     Types
403a7241f5fSBram Moolenaar	 - Integer, Char, Varchar, Date, DateTime, Timestamp, ...
404a7241f5fSBram Moolenaar
405a7241f5fSBram Moolenaar
406a7241f5fSBram Moolenaar4.2 Dynamic Mode				*sql-completion-dynamic*
407a7241f5fSBram Moolenaar----------------
408a7241f5fSBram MoolenaarDynamic mode populates the popups with data directly from a database.  In
409a7241f5fSBram Moolenaarorder for the dynamic feature to be enabled you must have the dbext.vim
410a7241f5fSBram Moolenaarplugin installed, (http://vim.sourceforge.net/script.php?script_id=356).
411a7241f5fSBram Moolenaar
412a7241f5fSBram MoolenaarDynamic mode is used by several features of the SQL completion plugin.
413a7241f5fSBram MoolenaarAfter installing the dbext plugin see the dbext-tutorial for additional
414a7241f5fSBram Moolenaarconfiguration and usage.  The dbext plugin allows the SQL completion plugin
415a7241f5fSBram Moolenaarto display a list of tables, procedures, views and columns. >
416a7241f5fSBram Moolenaar     Table List
417a7241f5fSBram Moolenaar	 - All tables for all schema owners
418a7241f5fSBram Moolenaar     Procedure List
419a7241f5fSBram Moolenaar	 - All stored procedures for all schema owners
420a7241f5fSBram Moolenaar     View List
421a7241f5fSBram Moolenaar	 - All stored procedures for all schema owners
422a7241f5fSBram Moolenaar     Column List
423a7241f5fSBram Moolenaar	 - For the selected table, the columns that are part of the table
424a7241f5fSBram Moolenaar
425a7241f5fSBram MoolenaarTo enable the popup, while in INSERT mode, use the following key combinations
426a7241f5fSBram Moolenaarfor each group (where <C-C> means hold the CTRL key down while pressing
427a7241f5fSBram Moolenaarthe space bar):
428a7241f5fSBram Moolenaar     Table List		   - <C-C>t
429a7241f5fSBram Moolenaar			   - <C-X><C-O> (the default map assumes tables)
430a7241f5fSBram Moolenaar     Stored Procedure List - <C-C>p
431a7241f5fSBram Moolenaar     View List		   - <C-C>v
432a7241f5fSBram Moolenaar     Column List	   - <C-C>c
433a7241f5fSBram Moolenaar
4348f3f58f2SBram Moolenaar     Drilling In / Out     - When viewing a popup window displaying the list
4358f3f58f2SBram Moolenaar			     of tables, you can press <Right>, this will
436a7241f5fSBram Moolenaar			     replace the table currently highlighted with
437a7241f5fSBram Moolenaar			     the column list for that table.
438a7241f5fSBram Moolenaar			   - When viewing a popup window displaying the list
4398f3f58f2SBram Moolenaar			     of columns, you can press <Left>, this will
440a7241f5fSBram Moolenaar			     replace the column list with the list of tables.
441a7241f5fSBram Moolenaar			   - This allows you to quickly drill down into a
442bf88493cSBram Moolenaar			     table to view its columns and back again.
443*d2ea7cf1SBram Moolenaar			   - <Right> and <Left> can also be chosen via
4448f3f58f2SBram Moolenaar			     your |.vimrc| >
4458f3f58f2SBram Moolenaar                                let g:ftplugin_sql_omni_key_right = '<Right>'
4468f3f58f2SBram Moolenaar                                let g:ftplugin_sql_omni_key_left  = '<Left>'
447a7241f5fSBram Moolenaar
448a7241f5fSBram MoolenaarThe SQL completion plugin caches various lists that are displayed in
449a7241f5fSBram Moolenaarthe popup window.  This makes the re-displaying of these lists very
450a7241f5fSBram Moolenaarfast.  If new tables or columns are added to the database it may become
451a7241f5fSBram Moolenaarnecessary to clear the plugins cache.  The default map for this is: >
452a7241f5fSBram Moolenaar    imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O>
453a7241f5fSBram Moolenaar
454a7241f5fSBram Moolenaar
455a7241f5fSBram Moolenaar4.3 SQL Tutorial				*sql-completion-tutorial*
456a7241f5fSBram Moolenaar----------------
457a7241f5fSBram Moolenaar
458a7241f5fSBram MoolenaarThis tutorial is designed to take you through the common features of the SQL
459a7241f5fSBram Moolenaarcompletion plugin so that: >
460a7241f5fSBram Moolenaar     a) You gain familiarity with the plugin
461a7241f5fSBram Moolenaar     b) You are introduced to some of the more common features
462a7241f5fSBram Moolenaar     c) Show how to customize it to your preferences
463a7241f5fSBram Moolenaar     d) Demonstrate "Best of Use" of the plugin (easiest way to configure).
464a7241f5fSBram Moolenaar
465a7241f5fSBram MoolenaarFirst, create a new buffer: >
466a7241f5fSBram Moolenaar     :e tutorial.sql
467a7241f5fSBram Moolenaar
468a7241f5fSBram Moolenaar
469a7241f5fSBram MoolenaarStatic features
470a7241f5fSBram Moolenaar---------------
471a7241f5fSBram MoolenaarTo take you through the various lists, simply enter insert mode, hit:
472a7241f5fSBram Moolenaar    <C-C>s   (show SQL statements)
473a7241f5fSBram MoolenaarAt this point, you can page down through the list until you find "select".
474a7241f5fSBram MoolenaarIf you are familiar with the item you are looking for, for example you know
475a7241f5fSBram Moolenaarthe statement begins with the letter "s".  You can type ahead (without the
476a7241f5fSBram Moolenaarquotes) "se" then press:
477a7241f5fSBram Moolenaar    <C-Space>t
478a7241f5fSBram MoolenaarAssuming "select" is highlighted in the popup list press <Enter> to choose
479a7241f5fSBram Moolenaarthe entry.  Now type:
480a7241f5fSBram Moolenaar    * fr<C-C>a (show all syntax items)
481a7241f5fSBram Moolenaarchoose "from" from the popup list.
482a7241f5fSBram Moolenaar
483a7241f5fSBram MoolenaarWhen writing stored procedures using the "type" list is useful.  It contains
484a7241f5fSBram Moolenaara list of all the database supported types.  This may or may not be true
485a7241f5fSBram Moolenaardepending on the syntax file you are using.  The SQL Anywhere syntax file
486a7241f5fSBram Moolenaar(sqlanywhere.vim) has support for this: >
487a7241f5fSBram Moolenaar     BEGIN
488a7241f5fSBram Moolenaar	DECLARE customer_id <C-C>T <-- Choose a type from the list
489a7241f5fSBram Moolenaar
490a7241f5fSBram Moolenaar
491a7241f5fSBram MoolenaarDynamic features
492a7241f5fSBram Moolenaar----------------
493a7241f5fSBram MoolenaarTo take advantage of the dynamic features you must first install the
494a7241f5fSBram Moolenaardbext.vim plugin (http://vim.sourceforge.net/script.php?script_id=356).  It
495a7241f5fSBram Moolenaaralso comes with a tutorial.  From the SQL completion plugin's perspective,
496a7241f5fSBram Moolenaarthe main feature dbext provides is a connection to a database.  dbext
497a7241f5fSBram Moolenaarconnection profiles are the most efficient mechanism to define connection
498a7241f5fSBram Moolenaarinformation.  Once connections have been setup, the SQL completion plugin
499a7241f5fSBram Moolenaaruses the features of dbext in the background to populate the popups.
500a7241f5fSBram Moolenaar
501a7241f5fSBram MoolenaarWhat follows assumes dbext.vim has been correctly configured, a simple test
502a7241f5fSBram Moolenaaris to run the command, :DBListTable.  If a list of tables is shown, you know
503a7241f5fSBram Moolenaardbext.vim is working as expected.  If not, please consult the dbext.txt
504a7241f5fSBram Moolenaardocumentation.
505a7241f5fSBram Moolenaar
506a7241f5fSBram MoolenaarAssuming you have followed the dbext-tutorial you can press <C-C>t to
507a7241f5fSBram Moolenaardisplay a list of tables.  There is a delay while dbext is creating the table
508a7241f5fSBram Moolenaarlist.  After the list is displayed press <C-W>.  This will remove both the
509a7241f5fSBram Moolenaarpopup window and the table name already chosen when the list became active. >
510a7241f5fSBram Moolenaar
511a7241f5fSBram Moolenaar 4.3.1 Table Completion:			*sql-completion-tables*
512a7241f5fSBram Moolenaar
513a7241f5fSBram MoolenaarPress <C-C>t to display a list of tables from within the database you
514a7241f5fSBram Moolenaarhave connected via the dbext plugin.
515a7241f5fSBram MoolenaarNOTE: All of the SQL completion popups support typing a prefix before pressing
516a7241f5fSBram Moolenaarthe key map.  This will limit the contents of the popup window to just items
517a7241f5fSBram Moolenaarbeginning with those characters.  >
518a7241f5fSBram Moolenaar
519a7241f5fSBram Moolenaar 4.3.2 Column Completion:			*sql-completion-columns*
520a7241f5fSBram Moolenaar
521a7241f5fSBram MoolenaarThe SQL completion plugin can also display a list of columns for particular
5222547aa93SBram Moolenaartables.  The column completion is triggered via <C-C>c.
523a7241f5fSBram Moolenaar
5248f3f58f2SBram MoolenaarNOTE: The following example uses <Right> to trigger a column list while
5258f3f58f2SBram Moolenaar      the popup window is active.
526a7241f5fSBram Moolenaar
527a7241f5fSBram MoolenaarExample of using column completion:
528a7241f5fSBram Moolenaar     - Press <C-C>t again to display the list of tables.
5298f3f58f2SBram Moolenaar     - When the list is displayed in the completion window, press <Right>,
530a7241f5fSBram Moolenaar       this will replace the list of tables, with a list of columns for the
531a7241f5fSBram Moolenaar       table highlighted (after the same short delay).
5328f3f58f2SBram Moolenaar     - If you press <Left>, this will again replace the column list with the
533a7241f5fSBram Moolenaar       list of tables.  This allows you to drill into tables and column lists
534a7241f5fSBram Moolenaar       very quickly.
5358f3f58f2SBram Moolenaar     - Press <Right> again while the same table is highlighted.  You will
536a7241f5fSBram Moolenaar       notice there is no delay since the column list has been cached.  If you
537a7241f5fSBram Moolenaar       change the schema of a cached table you can press <C-C>R, which
538a7241f5fSBram Moolenaar       clears the SQL completion cache.
5398f3f58f2SBram Moolenaar     - NOTE: <Right> and <Left> have been designed to work while the
540a7241f5fSBram Moolenaar       completion window is active.  If the completion popup window is
5418f3f58f2SBram Moolenaar       not active, a normal <Right> or <Left> will be executed.
542a7241f5fSBram Moolenaar
54306b5d516SBram MoolenaarLet's look at how we can build a SQL statement dynamically.  A select statement
544a7241f5fSBram Moolenaarrequires a list of columns.  There are two ways to build a column list using
545a7241f5fSBram Moolenaarthe SQL completion plugin. >
546a7241f5fSBram Moolenaar    One column at a time:
547a7241f5fSBram Moolenaar<       1. After typing SELECT press <C-C>t to display a list of tables.
548a7241f5fSBram Moolenaar	2. Choose a table from the list.
5498f3f58f2SBram Moolenaar	3. Press <Right> to display a list of columns.
550a7241f5fSBram Moolenaar	4. Choose the column from the list and press enter.
551a7241f5fSBram Moolenaar	5. Enter a "," and press <C-C>c.  Generating a column list
552a7241f5fSBram Moolenaar	   generally requires having the cursor on a table name.  The plugin
553a7241f5fSBram Moolenaar	   uses this name to determine what table to retrieve the column list.
554a7241f5fSBram Moolenaar	   In this step, since we are pressing <C-C>c without the cursor
555a7241f5fSBram Moolenaar	   on a table name the column list displayed will be for the previous
556a7241f5fSBram Moolenaar	   table.  Choose a different column and move on.
557a7241f5fSBram Moolenaar	6. Repeat step 5 as often as necessary. >
558a7241f5fSBram Moolenaar    All columns for a table:
559a7241f5fSBram Moolenaar<	1. After typing SELECT press <C-C>t to display a list of tables.
560a7241f5fSBram Moolenaar	2. Highlight the table you need the column list for.
561a7241f5fSBram Moolenaar	3. Press <Enter> to choose the table from the list.
562a7241f5fSBram Moolenaar	4. Press <C-C>l to request a comma separated list of all columns
563a7241f5fSBram Moolenaar	   for this table.
564a7241f5fSBram Moolenaar	5. Based on the table name chosen in step 3, the plugin attempts to
565a7241f5fSBram Moolenaar	   decide on a reasonable table alias.	You are then prompted to
566a7241f5fSBram Moolenaar	   either accept of change the alias.  Press OK.
567a7241f5fSBram Moolenaar	6. The table name is replaced with the column list of the table is
568a7241f5fSBram Moolenaar	   replaced with the comma separate list of columns with the alias
569a7241f5fSBram Moolenaar	   prepended to each of the columns.
570a7241f5fSBram Moolenaar	7. Step 3 and 4 can be replaced by pressing <C-C>L, which has
571a7241f5fSBram Moolenaar	   a <C-Y> embedded in the map to choose the currently highlighted
572a7241f5fSBram Moolenaar	   table in the list.
573a7241f5fSBram Moolenaar
574a7241f5fSBram MoolenaarThere is a special provision when writing select statements.  Consider the
575a7241f5fSBram Moolenaarfollowing statement: >
576a7241f5fSBram Moolenaar     select *
577a7241f5fSBram Moolenaar       from customer c,
578a7241f5fSBram Moolenaar	    contact cn,
579a7241f5fSBram Moolenaar	    department as dp,
580a7241f5fSBram Moolenaar	    employee e,
581a7241f5fSBram Moolenaar	    site_options so
582a7241f5fSBram Moolenaar      where c.
583a7241f5fSBram Moolenaar
584a7241f5fSBram MoolenaarIn INSERT mode after typing the final "c." which is an alias for the
585a7241f5fSBram Moolenaar"customer" table, you can press either <C-C>c or <C-X><C-O>.  This will
586a7241f5fSBram Moolenaarpopup a list of columns for the customer table.  It does this by looking back
587a7241f5fSBram Moolenaarto the beginning of the select statement and finding a list of the tables
588a7241f5fSBram Moolenaarspecified in the FROM clause.  In this case it notes that in the string
589a7241f5fSBram Moolenaar"customer c", "c" is an alias for the customer table.  The optional "AS"
590a7241f5fSBram Moolenaarkeyword is also supported, "customer AS c". >
591a7241f5fSBram Moolenaar
592a7241f5fSBram Moolenaar
593a7241f5fSBram Moolenaar 4.3.3 Procedure Completion:			*sql-completion-procedures*
594a7241f5fSBram Moolenaar
595a7241f5fSBram MoolenaarSimilar to the table list, <C-C>p, will display a list of stored
596a7241f5fSBram Moolenaarprocedures stored within the database. >
597a7241f5fSBram Moolenaar
598a7241f5fSBram Moolenaar 4.3.4 View Completion:				*sql-completion-views*
599a7241f5fSBram Moolenaar
600a7241f5fSBram MoolenaarSimilar to the table list, <C-C>v, will display a list of views in the
601a7241f5fSBram Moolenaardatabase.
602a7241f5fSBram Moolenaar
603a7241f5fSBram Moolenaar
604a7241f5fSBram Moolenaar4.4 Completion Customization			*sql-completion-customization*
605a7241f5fSBram Moolenaar----------------------------
606a7241f5fSBram Moolenaar
607a7241f5fSBram MoolenaarThe SQL completion plugin can be customized through various options set in
608a7241f5fSBram Moolenaaryour |vimrc|: >
609a7241f5fSBram Moolenaar    omni_sql_no_default_maps
610a7241f5fSBram Moolenaar<       - Default: This variable is not defined
611a7241f5fSBram Moolenaar	- If this variable is defined, no maps are created for OMNI
612a7241f5fSBram Moolenaar	  completion.  See |sql-completion-maps| for further discussion.
613a7241f5fSBram Moolenaar>
614a7241f5fSBram Moolenaar    omni_sql_use_tbl_alias
615a7241f5fSBram Moolenaar<	- Default: a
616a7241f5fSBram Moolenaar	- This setting is only used when generating a comma separated
617a7241f5fSBram Moolenaar	  column list.	By default the map is <C-C>l.  When generating
618a7241f5fSBram Moolenaar	  a column list, an alias can be prepended to the beginning of each
619a7241f5fSBram Moolenaar	  column, for example:	e.emp_id, e.emp_name.  This option has three
620a7241f5fSBram Moolenaar	  settings: >
621a7241f5fSBram Moolenaar		n - do not use an alias
622a7241f5fSBram Moolenaar		d - use the default (calculated) alias
623a7241f5fSBram Moolenaar		a - ask to confirm the alias name
624a7241f5fSBram Moolenaar<
625a7241f5fSBram Moolenaar	  An alias is determined following a few rules:
626a7241f5fSBram Moolenaar	       1.  If the table name has an '_', then use it as a separator: >
627a7241f5fSBram Moolenaar		   MY_TABLE_NAME --> MTN
628a7241f5fSBram Moolenaar		   my_table_name --> mtn
629a7241f5fSBram Moolenaar		   My_table_NAME --> MtN
630a7241f5fSBram Moolenaar<	       2.  If the table name does NOT contain an '_', but DOES use
631a7241f5fSBram Moolenaar		   mixed case then the case is used as a separator: >
632a7241f5fSBram Moolenaar		   MyTableName --> MTN
633a7241f5fSBram Moolenaar<	       3.  If the table name does NOT contain an '_', and does NOT
634a7241f5fSBram Moolenaar		   use mixed case then the first letter of the table is used: >
635a7241f5fSBram Moolenaar		   mytablename --> m
636a7241f5fSBram Moolenaar		   MYTABLENAME --> M
637a7241f5fSBram Moolenaar
638a7241f5fSBram Moolenaar    omni_sql_ignorecase
639f91787cbSBram Moolenaar<	- Default: Current setting for 'ignorecase'
640a7241f5fSBram Moolenaar	- Valid settings are 0 or 1.
641a7241f5fSBram Moolenaar	- When entering a few letters before initiating completion, the list
642a7241f5fSBram Moolenaar	  will be filtered to display only the entries which begin with the
643a7241f5fSBram Moolenaar	  list of characters.  When this option is set to 0, the list will be
644a7241f5fSBram Moolenaar	  filtered using case sensitivity. >
645a7241f5fSBram Moolenaar
646a7241f5fSBram Moolenaar    omni_sql_include_owner
647a7241f5fSBram Moolenaar<	- Default: 0, unless dbext.vim 3.00 has been installed
648a7241f5fSBram Moolenaar	- Valid settings are 0 or 1.
649a7241f5fSBram Moolenaar	- When completing tables, procedure or views and using dbext.vim 3.00
650a7241f5fSBram Moolenaar	  or higher the list of objects will also include the owner name.
651a7241f5fSBram Moolenaar	  When completing these objects and omni_sql_include_owner is enabled
652bf88493cSBram Moolenaar	  the owner name will be replaced. >
653a7241f5fSBram Moolenaar
654a7241f5fSBram Moolenaar    omni_sql_precache_syntax_groups
655a7241f5fSBram Moolenaar<	- Default:
656a7241f5fSBram Moolenaar	  ['syntax','sqlKeyword','sqlFunction','sqlOption','sqlType','sqlStatement']
657a7241f5fSBram Moolenaar	- sqlcomplete can be used in conjunction with other completion
658a7241f5fSBram Moolenaar	  plugins.  This is outlined at |sql-completion-filetypes|.  When the
659a7241f5fSBram Moolenaar	  filetype is changed temporarily to SQL, the sqlcompletion plugin
660a7241f5fSBram Moolenaar	  will cache the syntax groups listed in the List specified in this
661a7241f5fSBram Moolenaar	  option.
662a7241f5fSBram Moolenaar>
663a7241f5fSBram Moolenaar
664a7241f5fSBram Moolenaar4.5 SQL Maps					*sql-completion-maps*
665a7241f5fSBram Moolenaar------------
666a7241f5fSBram Moolenaar
667a7241f5fSBram MoolenaarThe default SQL maps have been described in other sections of this document in
668a7241f5fSBram Moolenaargreater detail.  Here is a list of the maps with a brief description of each.
669a7241f5fSBram Moolenaar
670a7241f5fSBram MoolenaarStatic Maps
671a7241f5fSBram Moolenaar-----------
672a7241f5fSBram MoolenaarThese are maps which use populate the completion list using Vim's syntax
673a7241f5fSBram Moolenaarhighlighting rules. >
674a7241f5fSBram Moolenaar    <C-C>a
675a7241f5fSBram Moolenaar<       - Displays all SQL syntax items. >
676a7241f5fSBram Moolenaar    <C-C>k
677a7241f5fSBram Moolenaar<       - Displays all SQL syntax items defined as 'sqlKeyword'. >
678a7241f5fSBram Moolenaar    <C-C>f
679a7241f5fSBram Moolenaar<       - Displays all SQL syntax items defined as 'sqlFunction. >
680a7241f5fSBram Moolenaar    <C-C>o
681a7241f5fSBram Moolenaar<       - Displays all SQL syntax items defined as 'sqlOption'. >
682a7241f5fSBram Moolenaar    <C-C>T
683a7241f5fSBram Moolenaar<       - Displays all SQL syntax items defined as 'sqlType'. >
684a7241f5fSBram Moolenaar    <C-C>s
685a7241f5fSBram Moolenaar<       - Displays all SQL syntax items defined as 'sqlStatement'. >
686a7241f5fSBram Moolenaar
687a7241f5fSBram MoolenaarDynamic Maps
688a7241f5fSBram Moolenaar------------
689a7241f5fSBram MoolenaarThese are maps which use populate the completion list using the dbext.vim
690a7241f5fSBram Moolenaarplugin. >
691a7241f5fSBram Moolenaar    <C-C>t
692a7241f5fSBram Moolenaar<       - Displays a list of tables. >
693a7241f5fSBram Moolenaar    <C-C>p
694a7241f5fSBram Moolenaar<       - Displays a list of procedures. >
695a7241f5fSBram Moolenaar    <C-C>v
696a7241f5fSBram Moolenaar<       - Displays a list of views. >
697a7241f5fSBram Moolenaar    <C-C>c
698a7241f5fSBram Moolenaar<       - Displays a list of columns for a specific table. >
699a7241f5fSBram Moolenaar    <C-C>l
700a7241f5fSBram Moolenaar<       - Displays a comma separated list of columns for a specific table. >
701a7241f5fSBram Moolenaar    <C-C>L
702a7241f5fSBram Moolenaar<       - Displays a comma separated list of columns for a specific table.
703a7241f5fSBram Moolenaar	  This should only be used when the completion window is active. >
7048f3f58f2SBram Moolenaar    <Right>
705a7241f5fSBram Moolenaar<	- Displays a list of columns for the table currently highlighted in
7068f3f58f2SBram Moolenaar	  the completion window.  <Right> is not recognized on most Unix
707a7241f5fSBram Moolenaar	  systems, so this maps is only created on the Windows platform.
708a7241f5fSBram Moolenaar	  If you would like the same feature on Unix, choose a different key
709a7241f5fSBram Moolenaar	  and make the same map in your vimrc. >
7108f3f58f2SBram Moolenaar    <Left>
711a7241f5fSBram Moolenaar<	- Displays the list of tables.
7128f3f58f2SBram Moolenaar	  <Left> is not recognized on most Unix systems, so this maps is
713a7241f5fSBram Moolenaar	  only created on the Windows platform.  If you would like the same
714a7241f5fSBram Moolenaar	  feature on Unix, choose a different key and make the same map in
715a7241f5fSBram Moolenaar	  your vimrc. >
716a7241f5fSBram Moolenaar    <C-C>R
717a7241f5fSBram Moolenaar<	- This maps removes all cached items and forces the SQL completion
718a7241f5fSBram Moolenaar	  to regenerate the list of items.
719a7241f5fSBram Moolenaar
720a7241f5fSBram MoolenaarCustomizing Maps
721a7241f5fSBram Moolenaar----------------
722a7241f5fSBram MoolenaarYou can create as many additional key maps as you like.  Generally, the maps
723a7241f5fSBram Moolenaarwill be specifying different syntax highlight groups.
724a7241f5fSBram Moolenaar
725a7241f5fSBram MoolenaarIf you do not wish the default maps created or the key choices do not work on
726a7241f5fSBram Moolenaaryour platform (often a case on *nix) you define the following variable in
727a7241f5fSBram Moolenaaryour |vimrc|: >
728a7241f5fSBram Moolenaar    let g:omni_sql_no_default_maps = 1
729a7241f5fSBram Moolenaar
7302547aa93SBram MoolenaarDo not edit ftplugin/sql.vim directly!  If you change this file your changes
731a7241f5fSBram Moolenaarwill be over written on future updates.  Vim has a special directory structure
732a7241f5fSBram Moolenaarwhich allows you to make customizations without changing the files that are
733a7241f5fSBram Moolenaarincluded with the Vim distribution.  If you wish to customize the maps
734a7241f5fSBram Moolenaarcreate an after/ftplugin/sql.vim (see |after-directory|) and place the same
735a7241f5fSBram Moolenaarmaps from the ftplugin/sql.vim in it using your own key strokes.  <C-C> was
736a7241f5fSBram Moolenaarchosen since it will work on both Windows and *nix platforms.  On the windows
737a7241f5fSBram Moolenaarplatform you can also use <C-Space> or ALT keys.
738a7241f5fSBram Moolenaar
739a7241f5fSBram Moolenaar
740a7241f5fSBram Moolenaar4.6 Using with other filetypes			*sql-completion-filetypes*
741a7241f5fSBram Moolenaar------------------------------
742a7241f5fSBram Moolenaar
743a7241f5fSBram MoolenaarMany times SQL can be used with different filetypes.  For example Perl, Java,
744a7241f5fSBram MoolenaarPHP, Javascript can all interact with a database.  Often you need both the SQL
74506b5d516SBram Moolenaarcompletion and the completion capabilities for the current language you are
74606b5d516SBram Moolenaarediting.
747a7241f5fSBram Moolenaar
748a7241f5fSBram MoolenaarThis can be enabled easily with the following steps (assuming a Perl file): >
749a7241f5fSBram Moolenaar    1.  :e test.pl
750a7241f5fSBram Moolenaar    2.  :set filetype=sql
751a7241f5fSBram Moolenaar    3.  :set ft=perl
752a7241f5fSBram Moolenaar
753a7241f5fSBram MoolenaarStep 1
754a7241f5fSBram Moolenaar------
755a7241f5fSBram MoolenaarBegins by editing a Perl file.  Vim automatically sets the filetype to
756a7241f5fSBram Moolenaar"perl".  By default, Vim runs the appropriate filetype file
757a7241f5fSBram Moolenaarftplugin/perl.vim.  If you are using the syntax completion plugin by following
758a7241f5fSBram Moolenaarthe directions at |ft-syntax-omni| then the |'omnifunc'| option has been set to
759a7241f5fSBram Moolenaar"syntax#Complete".  Pressing <C-X><C-O> will display the omni popup containing
760a7241f5fSBram Moolenaarthe syntax items for Perl.
761a7241f5fSBram Moolenaar
762a7241f5fSBram MoolenaarStep 2
763a7241f5fSBram Moolenaar------
764a7241f5fSBram MoolenaarManually setting the filetype to 'sql' will also fire the appropriate filetype
765a7241f5fSBram Moolenaarfiles ftplugin/sql.vim.  This file will define a number of buffer specific
766a7241f5fSBram Moolenaarmaps for SQL completion, see |sql-completion-maps|.  Now these maps have
767a7241f5fSBram Moolenaarbeen created and the SQL completion plugin has been initialized.  All SQL
768a7241f5fSBram Moolenaarsyntax items have been cached in preparation.  The SQL filetype script detects
769a7241f5fSBram Moolenaarwe are attempting to use two different completion plugins.  Since the SQL maps
770a7241f5fSBram Moolenaarbegin with <C-C>, the maps will toggle the |'omnifunc'| when in use.  So you
771a7241f5fSBram Moolenaarcan use <C-X><C-O> to continue using the completion for Perl (using the syntax
772a7241f5fSBram Moolenaarcompletion plugin) and <C-C> to use the SQL completion features.
773a7241f5fSBram Moolenaar
774a7241f5fSBram MoolenaarStep 3
775a7241f5fSBram Moolenaar------
776a7241f5fSBram MoolenaarSetting the filetype back to Perl sets all the usual "perl" related items back
777a7241f5fSBram Moolenaaras they were.
778a7241f5fSBram Moolenaar
779a7241f5fSBram Moolenaar
78091f84f6eSBram Moolenaarvim:tw=78:ts=8:noet:ft=help:norl:
781