代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>ft_sql - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>
<body>
<header>
<div class="header">
<a href="http://vim-jp.org/">vim-jp</a>
/ <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
/ ft_sql<br />
<a name="top"></a><h1>ft_sql - Vim Documentation</h1>
<a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
</div>
</header>
<nav>
<dl>
<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>
<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>
<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>
<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>
<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>
<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>
<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>
<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>
<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>
<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>
<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>
<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>
<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>
<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>
<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>
<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>
<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>
</dl>
</nav>
<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="ft_sql.html" name="ft_sql.txt">ft_sql.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2013 May 15<br>
<br>
by David Fishburn<br>
<br>
This is a filetype plugin to work with SQL files.<br>
<br>
The Structured Query Language (SQL) is a standard which specifies statements<br>
that allow a user to interact with a relational database. Vim includes<br>
features for navigation, indentation and syntax highlighting.<br>
<br>
1. Navigation <a class="Identifier" href="ft_sql.html#sql-navigation">sql-navigation</a><br>
1.1 Matchit <a class="Identifier" href="ft_sql.html#sql-matchit">sql-matchit</a><br>
1.2 Text Object Motions <a class="Identifier" href="ft_sql.html#sql-object-motions">sql-object-motions</a><br>
1.3 Predefined Object Motions <a class="Identifier" href="ft_sql.html#sql-predefined-objects">sql-predefined-objects</a><br>
1.4 Macros <a class="Identifier" href="ft_sql.html#sql-macros">sql-macros</a><br>
2. SQL Dialects <a class="Identifier" href="ft_sql.html#sql-dialects">sql-dialects</a><br>
2.1 SQLSetType <a class="Identifier" href="ft_sql.html#SQLSetType">SQLSetType</a><br>
2.2 SQLGetType <a class="Identifier" href="ft_sql.html#SQLGetType">SQLGetType</a><br>
2.3 SQL Dialect Default <a class="Identifier" href="ft_sql.html#sql-type-default">sql-type-default</a><br>
3. Adding new SQL Dialects <a class="Identifier" href="ft_sql.html#sql-adding-dialects">sql-adding-dialects</a><br>
4. OMNI SQL Completion <a class="Identifier" href="ft_sql.html#sql-completion">sql-completion</a><br>
4.1 Static mode <a class="Identifier" href="ft_sql.html#sql-completion-static">sql-completion-static</a><br>
4.2 Dynamic mode <a class="Identifier" href="ft_sql.html#sql-completion-dynamic">sql-completion-dynamic</a><br>
4.3 Tutorial <a class="Identifier" href="ft_sql.html#sql-completion-tutorial">sql-completion-tutorial</a><br>
4.3.1 Complete Tables <a class="Identifier" href="ft_sql.html#sql-completion-tables">sql-completion-tables</a><br>
4.3.2 Complete Columns <a class="Identifier" href="ft_sql.html#sql-completion-columns">sql-completion-columns</a><br>
4.3.3 Complete Procedures <a class="Identifier" href="ft_sql.html#sql-completion-procedures">sql-completion-procedures</a><br>
4.3.4 Complete Views <a class="Identifier" href="ft_sql.html#sql-completion-views">sql-completion-views</a><br>
4.4 Completion Customization <a class="Identifier" href="ft_sql.html#sql-completion-customization">sql-completion-customization</a><br>
4.5 SQL Maps <a class="Identifier" href="ft_sql.html#sql-completion-maps">sql-completion-maps</a><br>
4.6 Using with other filetypes <a class="Identifier" href="ft_sql.html#sql-completion-filetypes">sql-completion-filetypes</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Navigation <a class="Constant" href="ft_sql.html#sql-navigation" name="sql-navigation">sql-navigation</a><br>
<br>
The SQL ftplugin provides a number of options to assist with file<br>
navigation.<br>
<br>
<br>
1.1 Matchit <a class="Constant" href="ft_sql.html#sql-matchit" name="sql-matchit">sql-matchit</a><br>
<span class="PreProc">-----------</span><br>
The matchit plugin (<span class="Constant"><a href="http://www.vim.org/scripts/script.php?script_id=39">http://www.vim.org/scripts/script.php?script_id=39</a></span>)<br>
provides many additional features and can be customized for different<br>
languages. The matchit plugin is configured by defining a local<br>
buffer variable, b:match_words. Pressing the % key while on various<br>
keywords will move the cursor to its match. For example, if the cursor<br>
is on an "if", pressing % will cycle between the "else", "elseif" and<br>
"end if" keywords.<br>
<br>
The following keywords are supported:<br>
<div class="helpExample"> if<br>
elseif | elsif<br>
else [if]<br>
end if</div>
<br>
<div class="helpExample"> [while condition] loop<br>
leave<br>
break<br>
continue<br>
exit<br>
end loop</div>
<br>
<div class="helpExample"> for<br>
leave<br>
break<br>
continue<br>
exit<br>
end loop</div>
<br>
<div class="helpExample"> do<br>
statements<br>
doend</div>
<br>
<div class="helpExample"> case<br>
when<br>
when<br>
default<br>
end case</div>
<br>
<div class="helpExample"> merge<br>
when not matched<br>
when matched</div>
<br>
<div class="helpExample"> create[ or replace] procedure|function|event<br>
returns</div>
<br>
<br>
1.2 Text Object Motions <a class="Constant" href="ft_sql.html#sql-object-motions" name="sql-object-motions">sql-object-motions</a><br>
<span class="PreProc">-----------------------</span><br>
Vim has a number of predefined keys for working with text <a class="Identifier" href="motion.html#object-motions">object-motions</a>.<br>
This filetype plugin attempts to translate these keys to maps which make sense<br>
for the SQL language.<br>
<br>
The following <a class="Identifier" href="intro.html#Normal">Normal</a> mode and <a class="Identifier" href="visual.html#Visual">Visual</a> mode maps exist (when you edit a SQL<br>
file):<br>
<div class="helpExample"> ]] move forward to the next 'begin'<br>
[[ move backwards to the previous 'begin'<br>
][ move forward to the next 'end'<br>
[] move backwards to the previous 'end'</div>
<br>
<br>
1.3 Predefined Object Motions <a class="Constant" href="ft_sql.html#sql-predefined-objects" name="sql-predefined-objects">sql-predefined-objects</a><br>
<span class="PreProc">-----------------------------</span><br>
Most relational databases support various standard features, tables, indices,<br>
triggers and stored procedures. Each vendor also has a variety of proprietary<br>
objects. The next set of maps have been created to help move between these<br>
objects. Depends on which database vendor you are using, the list of objects<br>
must be configurable. The filetype plugin attempts to define many of the<br>
standard objects, plus many additional ones. In order to make this as<br>
flexible as possible, you can override the list of objects from within your<br>
<a class="Identifier" href="starting.html#vimrc">vimrc</a> with the following:<br>
<div class="helpExample"> let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' .<br>
\ ',schema,service,publication,database,datatype,domain' .<br>
\ ',index,subscription,synchronization,view,variable'</div>
<br>
The following <a class="Identifier" href="intro.html#Normal">Normal</a> mode and <a class="Identifier" href="visual.html#Visual">Visual</a> mode maps have been created which use<br>
the above list:<br>
<div class="helpExample"> ]} move forward to the next 'create <object name>'<br>
[{ move backward to the previous 'create <object name>'</div>
<br>
Repeatedly pressing ]} will cycle through each of these create statements:<br>
<div class="helpExample"> create table t1 (<br>
...<br>
);</div>
<br>
<div class="helpExample"> create procedure p1<br>
begin<br>
...<br>
end;</div>
<br>
<div class="helpExample"> create index i1 on t1 (c1);</div>
<br>
The default setting for g:ftplugin_sql_objects is:<br>
<div class="helpExample"> let g:ftplugin_sql_objects = 'function,procedure,event,' .<br>
\ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' .<br>
\ 'table,trigger' .<br>
\ ',schema,service,publication,database,datatype,domain' .<br>
\ ',index,subscription,synchronization,view,variable'</div>
<br>
The above will also handle these cases:<br>
<div class="helpExample"> create table t1 (<br>
...<br>
);<br>
create existing table t2 (<br>
...<br>
);<br>
create global temporary table t3 (<br>
...<br>
);</div>
<br>
By default, the ftplugin only searches for CREATE statements. You can also<br>
override this via your <a class="Identifier" href="starting.html#vimrc">vimrc</a> with the following:<br>
<div class="helpExample"> let g:ftplugin_sql_statements = 'create,alter'</div>
<br>
The filetype plugin defines three types of comments:<br>
<div class="helpExample"> 1. --<br>
2. //<br>
3. /*<br>
*<br>
*/</div>
<br>
The following <a class="Identifier" href="intro.html#Normal">Normal</a> mode and <a class="Identifier" href="visual.html#Visual">Visual</a> mode maps have been created to work<br>
with comments:<br>
<div class="helpExample"> ]" move forward to the beginning of a comment<br>
[" move forward to the end of a comment</div>
<br>
<br>
<br>
1.4 Macros <a class="Constant" href="ft_sql.html#sql-macros" name="sql-macros">sql-macros</a><br>
<span class="PreProc">----------</span><br>
Vim's feature to find macro definitions, <a class="Identifier" href="options.html#'define'">'define'</a>, is supported using this<br>
regular expression:<br>
<div class="helpExample"> \c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\></div>
<br>
This addresses the following code:<br>
<div class="helpExample"> CREATE VARIABLE myVar1 INTEGER;</div>
<br>
<div class="helpExample"> CREATE PROCEDURE sp_test(<br>
IN myVar2 INTEGER,<br>
OUT myVar3 CHAR(30),<br>
INOUT myVar4 NUMERIC(20,0)<br>
)<br>
BEGIN<br>
DECLARE myVar5 INTEGER;</div>
<br>
<div class="helpExample"> SELECT c1, c2, c3<br>
INTO myVar2, myVar3, myVar4<br>
FROM T1<br>
WHERE c4 = myVar1;<br>
END;</div>
<br>
Place your cursor on "myVar1" on this line:<br>
<div class="helpExample"> WHERE c4 = myVar1;<br>
^</div>
<br>
Press any of the following keys:<br>
<div class="helpExample"> [d<br>
[D<br>
[CTRL-D</div>
<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. SQL Dialects <a class="Constant" href="ft_sql.html#sql-dialects" name="sql-dialects">sql-dialects</a> <a class="Constant" href="ft_sql.html#sql-types" name="sql-types">sql-types</a><br>
<a class="Constant" href="ft_sql.html#sybase" name="sybase">sybase</a> <a class="Constant" href="ft_sql.html#TSQL" name="TSQL">TSQL</a> <a class="Constant" href="ft_sql.html#Transact-SQL" name="Transact-SQL">Transact-SQL</a><br>
<a class="Constant" href="ft_sql.html#sqlanywhere" name="sqlanywhere">sqlanywhere</a><br>
<a class="Constant" href="ft_sql.html#oracle" name="oracle">oracle</a> <a class="Constant" href="ft_sql.html#plsql" name="plsql">plsql</a> <a class="Constant" href="ft_sql.html#sqlj" name="sqlj">sqlj</a><br>
<a class="Constant" href="ft_sql.html#sqlserver" name="sqlserver">sqlserver</a><br>
<a class="Constant" href="ft_sql.html#mysql" name="mysql">mysql</a> <a class="Constant" href="ft_sql.html#postgresql" name="postgresql">postgresql</a> <a class="Constant" href="ft_sql.html#psql" name="psql">psql</a><br>
<a class="Constant" href="ft_sql.html#informix" name="informix">informix</a><br>
<br>
All relational databases support SQL. There is a portion of SQL that is<br>
portable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a<br>
great deal of vendor specific extensions to SQL. Oracle supports the<br>
"CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE<br>
statement and the procedural language (for stored procedures and triggers).<br>
<br>
The default Vim distribution ships with syntax highlighting based on Oracle's<br>
PL/SQL. The default SQL indent script works for Oracle and SQL Anywhere.<br>
The default filetype plugin works for all vendors and should remain vendor<br>
neutral, but extendable.<br>
<br>
Vim currently has support for a variety of different vendors, currently this<br>
is via syntax scripts. Unfortunately, to flip between different syntax rules<br>
you must either create:<br>
1. New filetypes<br>
2. Custom autocmds<br>
3. Manual steps / commands<br>
<br>
The majority of people work with only one vendor's database product, it would<br>
be nice to specify a default in your <a class="Identifier" href="starting.html#vimrc">vimrc</a>.<br>
<br>
<br>
2.1 SQLSetType <a class="Constant" href="ft_sql.html#sqlsettype" name="sqlsettype">sqlsettype</a> <a class="Constant" href="ft_sql.html#SQLSetType" name="SQLSetType">SQLSetType</a><br>
<span class="PreProc">--------------</span><br>
For the people that work with many different databases, it is nice to be<br>
able to flip between the various vendors rules (indent, syntax) on a per<br>
buffer basis, at any time. The ftplugin/sql.vim file defines this function:<br>
<div class="helpExample"> SQLSetType</div>
<br>
Executing this function without any parameters will set the indent and syntax<br>
scripts back to their defaults, see <a class="Identifier" href="ft_sql.html#sql-type-default">sql-type-default</a>. If you have turned<br>
off Vi's compatibility mode, <a class="Identifier" href="options.html#'compatible'">'compatible'</a>, you can use the <span class="Special"><Tab></span> key to<br>
complete the optional parameter.<br>
<br>
After typing the function name and a space, you can use the completion to<br>
supply a parameter. The function takes the name of the Vim script you want to<br>
source. Using the <a class="Identifier" href="cmdline.html#cmdline-completion">cmdline-completion</a> feature, the SQLSetType function will<br>
search the <a class="Identifier" href="options.html#'runtimepath'">'runtimepath'</a> for all Vim scripts with a name containing <span class="MissingTag">'sql'</span>.<br>
This takes the guess work out of the spelling of the names. The following are<br>
examples:<br>
<div class="helpExample"> :SQLSetType<br>
:SQLSetType sqloracle<br>
:SQLSetType sqlanywhere<br>
:SQLSetType sqlinformix<br>
:SQLSetType mysql</div>
<br>
The easiest approach is to the use <span class="Special"><Tab></span> character which will first complete<br>
the command name (SQLSetType), after a space and another <span class="Special"><Tab></span>, display a list<br>
of available Vim script names:<br>
<div class="helpExample"> :SQL<Tab><space><Tab></div>
<br>
<br>
2.2 SQLGetType <a class="Constant" href="ft_sql.html#sqlgettype" name="sqlgettype">sqlgettype</a> <a class="Constant" href="ft_sql.html#SQLGetType" name="SQLGetType">SQLGetType</a><br>
<span class="PreProc">--------------</span><br>
At anytime you can determine which SQL dialect you are using by calling the<br>
SQLGetType command. The ftplugin/sql.vim file defines this function:<br>
<div class="helpExample"> SQLGetType</div>
<br>
This will echo:<br>
<div class="helpExample"> Current SQL dialect in use:sqlanywhere</div>
<br>
<br>
2.3 SQL Dialect Default <a class="Constant" href="ft_sql.html#sql-type-default" name="sql-type-default">sql-type-default</a><br>
<span class="PreProc">-----------------------</span><br>
As mentioned earlier, the default syntax rules for Vim is based on Oracle<br>
(PL/SQL). You can override this default by placing one of the following in<br>
your <a class="Identifier" href="starting.html#vimrc">vimrc</a>:<br>
<div class="helpExample"> let g:sql_type_default = 'sqlanywhere'<br>
let g:sql_type_default = 'sqlinformix'<br>
let g:sql_type_default = 'mysql'</div>
<br>
If you added the following to your <a class="Identifier" href="starting.html#vimrc">vimrc</a>:<br>
<div class="helpExample"> let g:sql_type_default = 'sqlinformix'</div>
<br>
The next time edit a SQL file the following scripts will be automatically<br>
loaded by Vim:<br>
<div class="helpExample"> ftplugin/sql.vim<br>
syntax/sqlinformix.vim<br>
indent/sql.vim</div>
<br>
Notice indent/sqlinformix.sql was not loaded. There is no indent file<br>
for Informix, Vim loads the default files if the specified files does not<br>
exist.<br>
<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Adding new SQL Dialects <a class="Constant" href="ft_sql.html#sql-adding-dialects" name="sql-adding-dialects">sql-adding-dialects</a><br>
<br>
If you begin working with a SQL dialect which does not have any customizations<br>
available with the default Vim distribution you can check <span class="Constant"><a href="http://www.vim.org">http://www.vim.org</a></span><br>
to see if any customization currently exist. If not, you can begin by cloning<br>
an existing script. Read <a class="Identifier" href="filetype.html#filetype-plugins">filetype-plugins</a> for more details.<br>
<br>
To help identify these scripts, try to create the files with a "sql" prefix.<br>
If you decide you wish to create customizations for the SQLite database, you<br>
can create any of the following:<br>
<div class="helpExample"> Unix<br>
~/.vim/syntax/sqlite.vim<br>
~/.vim/indent/sqlite.vim<br>
Windows<br>
$VIM/vimfiles/syntax/sqlite.vim<br>
$VIM/vimfiles/indent/sqlite.vim</div>
<br>
No changes are necessary to the SQLSetType function. It will automatically<br>
pickup the new SQL files and load them when you issue the SQLSetType command.<br>
<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. OMNI SQL Completion <a class="Constant" href="ft_sql.html#sql-completion" name="sql-completion">sql-completion</a><br>
<a class="Constant" href="ft_sql.html#omni-sql-completion" name="omni-sql-completion">omni-sql-completion</a><br>
<br>
Vim 7 includes a code completion interface and functions which allows plugin<br>
developers to build in code completion for any language. Vim 7 includes<br>
code completion for the SQL language.<br>
<br>
There are two modes to the SQL completion plugin, static and dynamic. The<br>
static mode populates the popups with the data generated from current syntax<br>
highlight rules. The dynamic mode populates the popups with data retrieved<br>
directly from a database. This includes, table lists, column lists,<br>
procedures names and more.<br>
<br>
4.1 Static Mode <a class="Constant" href="ft_sql.html#sql-completion-static" name="sql-completion-static">sql-completion-static</a><br>
<span class="PreProc">---------------</span><br>
The static popups created contain items defined by the active syntax rules<br>
while editing a file with a filetype of SQL. The plugin defines (by default)<br>
various maps to help the user refine the list of items to be displayed.<br>
The defaults static maps are:<br>
<div class="helpExample"> imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O><br>
imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O><br>
imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O><br>
imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O><br>
imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O><br>
imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O></div>
<br>
The use of "<span class="Special"><C-C></span>" can be user chosen by using the following in your <a class="Identifier" href="starting.html#.vimrc">.vimrc</a> as it <br>
may not work properly on all platforms:<br>
<div class="helpExample"> let g:ftplugin_sql_omni_key = '<C-C>'</div>
<br>
The static maps (which are based on the syntax highlight groups) follow this<br>
format:<br>
<div class="helpExample"> imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O><br>
imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword\w*')<CR><C-X><C-O></div>
<br>
This command breaks down as:<br>
<div class="helpExample"> imap - Create an insert map<br>
<buffer> - Only for this buffer<br>
<C-C>k - Your choice of key map<br>
<C-\><C-O> - Execute one command, return to Insert mode<br>
:call sqlcomplete#Map( - Allows the SQL completion plugin to perform some<br>
housekeeping functions to allow it to be used in<br>
conjunction with other completion plugins.<br>
Indicate which item you want the SQL completion<br>
plugin to complete.<br>
In this case we are asking the plugin to display<br>
items from the syntax highlight group<br>
'sqlKeyword'.<br>
You can view a list of highlight group names to<br>
choose from by executing the<br>
:syntax list<br>
command while editing a SQL file.<br>
'sqlKeyword' - Display the items for the sqlKeyword highlight<br>
group<br>
'sqlKeyword\w*' - A second option available with Vim 7.4 which<br>
uses a regular expression to determine which<br>
syntax groups to use<br>
)<CR> - Execute the :let command<br>
<C-X><C-O> - Trigger the standard omni completion key stroke.<br>
Passing in 'sqlKeyword' instructs the SQL<br>
completion plugin to populate the popup with<br>
items from the sqlKeyword highlight group. The<br>
plugin will also cache this result until Vim is<br>
restarted. The syntax list is retrieved using<br>
the syntaxcomplete plugin.</div>
<br>
Using the <a class="Type" href="options.html#'syntax'">'syntax'</a> keyword is a special case. This instructs the<br>
syntaxcomplete plugin to retrieve all syntax items. So this will effectively<br>
work for any of Vim's SQL syntax files. At the time of writing this includes<br>
10 different syntax files for the different dialects of SQL (see section 3<br>
above, <a class="Identifier" href="ft_sql.html#sql-dialects">sql-dialects</a>).<br>
<br>
Here are some examples of the entries which are pulled from the syntax files:<br>
<div class="helpExample"> All<br>
- Contains the contents of all syntax highlight groups<br>
Statements<br>
- Select, Insert, Update, Delete, Create, Alter, ...<br>
Functions<br>
- Min, Max, Trim, Round, Date, ...<br>
Keywords<br>
- Index, Database, Having, Group, With<br>
Options<br>
- Isolation_level, On_error, Qualify_owners, Fire_triggers, ...<br>
Types<br>
- Integer, Char, Varchar, Date, DateTime, Timestamp, ...</div>
<br>
<br>
4.2 Dynamic Mode <a class="Constant" href="ft_sql.html#sql-completion-dynamic" name="sql-completion-dynamic">sql-completion-dynamic</a><br>
<span class="PreProc">----------------</span><br>
Dynamic mode populates the popups with data directly from a database. In<br>
order for the dynamic feature to be enabled you must have the dbext.vim<br>
plugin installed, (<span class="Constant"><a href="http://vim.sourceforge.net/script.php?script_id=356">http://vim.sourceforge.net/script.php?script_id=356</a></span>).<br>
<br>
Dynamic mode is used by several features of the SQL completion plugin.<br>
After installing the dbext plugin see the dbext-tutorial for additional<br>
configuration and usage. The dbext plugin allows the SQL completion plugin<br>
to display a list of tables, procedures, views and columns.<br>
<div class="helpExample"> Table List<br>
- All tables for all schema owners<br>
Procedure List<br>
- All stored procedures for all schema owners<br>
View List<br>
- All stored procedures for all schema owners<br>
Column List<br>
- For the selected table, the columns that are part of the table</div>
<br>
To enable the popup, while in INSERT mode, use the following key combinations<br>
for each group (where <span class="Special"><C-C></span> means hold the CTRL key down while pressing<br>
the space bar):<br>
Table List - <span class="Special"><C-C></span>t<br>
- <span class="Special"><C-X><C-O></span> (the default map assumes tables)<br>
Stored Procedure List - <span class="Special"><C-C></span>p<br>
View List - <span class="Special"><C-C></span>v<br>
Column List - <span class="Special"><C-C></span>c<br>
<br>
Drilling In / Out - When viewing a popup window displaying the list<br>
of tables, you can press <span class="Special"><Right></span>, this will<br>
replace the table currently highlighted with<br>
the column list for that table.<br>
- When viewing a popup window displaying the list<br>
of columns, you can press <span class="Special"><Left></span>, this will<br>
replace the column list with the list of tables.<br>
- This allows you to quickly drill down into a<br>
table to view its columns and back again.<br>
- <span class="Special"><Right></span> and <span class="Special"><Left></span> can be also be chosen via<br>
your <a class="Identifier" href="starting.html#.vimrc">.vimrc</a><br>
<div class="helpExample"> let g:ftplugin_sql_omni_key_right = '<Right>'<br>
let g:ftplugin_sql_omni_key_left = '<Left>'</div>
<br>
The SQL completion plugin caches various lists that are displayed in<br>
the popup window. This makes the re-displaying of these lists very<br>
fast. If new tables or columns are added to the database it may become<br>
necessary to clear the plugins cache. The default map for this is:<br>
<div class="helpExample"> imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O></div>
<br>
<br>
4.3 SQL Tutorial <a class="Constant" href="ft_sql.html#sql-completion-tutorial" name="sql-completion-tutorial">sql-completion-tutorial</a><br>
<span class="PreProc">----------------</span><br>
<br>
This tutorial is designed to take you through the common features of the SQL<br>
completion plugin so that:<br>
<div class="helpExample"> a) You gain familiarity with the plugin<br>
b) You are introduced to some of the more common features<br>
c) Show how to customize it to your preferences<br>
d) Demonstrate "Best of Use" of the plugin (easiest way to configure).</div>
<br>
First, create a new buffer:<br>
<div class="helpExample"> :e tutorial.sql</div>
<br>
<br>
Static features<br>
<span class="PreProc">---------------</span><br>
To take you through the various lists, simply enter insert mode, hit:<br>
<span class="Special"><C-C></span>s (show SQL statements)<br>
At this point, you can page down through the list until you find "select".<br>
If you are familiar with the item you are looking for, for example you know<br>
the statement begins with the letter "s". You can type ahead (without the<br>
quotes) "se" then press:<br>
<span class="Special"><C-Space></span>t<br>
Assuming "select" is highlighted in the popup list press <span class="Special"><Enter></span> to choose<br>
the entry. Now type:<br>
<span class="Statement"> </span>* fr<span class="Special"><C-C></span>a (show all syntax items)<br>
choose "from" from the popup list.<br>
<br>
When writing stored procedures using the "type" list is useful. It contains<br>
a list of all the database supported types. This may or may not be true<br>
depending on the syntax file you are using. The SQL Anywhere syntax file<br>
(sqlanywhere.vim) has support for this:<br>
<div class="helpExample"> BEGIN<br>
DECLARE customer_id <C-C>T <-- Choose a type from the list</div>
<br>
<br>
Dynamic features<br>
<span class="PreProc">----------------</span><br>
To take advantage of the dynamic features you must first install the<br>
dbext.vim plugin (<span class="Constant"><a href="http://vim.sourceforge.net/script.php?script_id=356">http://vim.sourceforge.net/script.php?script_id=356</a></span>). It<br>
also comes with a tutorial. From the SQL completion plugin's perspective,<br>
the main feature dbext provides is a connection to a database. dbext<br>
connection profiles are the most efficient mechanism to define connection<br>
information. Once connections have been setup, the SQL completion plugin<br>
uses the features of dbext in the background to populate the popups.<br>
<br>
What follows assumes dbext.vim has been correctly configured, a simple test<br>
is to run the command, :DBListTable. If a list of tables is shown, you know<br>
dbext.vim is working as expected. If not, please consult the dbext.txt<br>
documentation.<br>
<br>
Assuming you have followed the dbext-tutorial you can press <span class="Special"><C-C></span>t to<br>
display a list of tables. There is a delay while dbext is creating the table<br>
list. After the list is displayed press <span class="Special"><C-W></span>. This will remove both the<br>
popup window and the table name already chosen when the list became active.<br>
<br>
<div class="helpExample"> 4.3.1 Table Completion: *sql-completion-tables*</div>
<br>
Press <span class="Special"><C-C></span>t to display a list of tables from within the database you<br>
have connected via the dbext plugin.<br>
<span class="Todo">NOTE</span>: All of the SQL completion popups support typing a prefix before pressing<br>
the key map. This will limit the contents of the popup window to just items<br>
beginning with those characters. <br>
<br>
<div class="helpExample"> 4.3.2 Column Completion: *sql-completion-columns*</div>
<br>
The SQL completion plugin can also display a list of columns for particular<br>
tables. The column completion is trigger via <span class="Special"><C-C></span>c.<br>
<br>
<span class="Todo">NOTE</span>: The following example uses <span class="Special"><Right></span> to trigger a column list while<br>
the popup window is active. <br>
<br>
Example of using column completion:<br>
- Press <span class="Special"><C-C></span>t again to display the list of tables.<br>
- When the list is displayed in the completion window, press <span class="Special"><Right></span>,<br>
this will replace the list of tables, with a list of columns for the<br>
table highlighted (after the same short delay).<br>
- If you press <span class="Special"><Left></span>, this will again replace the column list with the<br>
list of tables. This allows you to drill into tables and column lists<br>
very quickly.<br>
- Press <span class="Special"><Right></span> again while the same table is highlighted. You will<br>
notice there is no delay since the column list has been cached. If you<br>
change the schema of a cached table you can press <span class="Special"><C-C></span>R, which<br>
clears the SQL completion cache.<br>
- <span class="Todo">NOTE</span>: <span class="Special"><Right></span> and <span class="Special"><Left></span> have been designed to work while the<br>
completion window is active. If the completion popup window is<br>
not active, a normal <span class="Special"><Right></span> or <span class="Special"><Left></span> will be executed.<br>
<br>
Let's look at how we can build a SQL statement dynamically. A select statement<br>
requires a list of columns. There are two ways to build a column list using<br>
the SQL completion plugin.<br>
<div class="helpExample"> One column at a time:</div>
1. After typing SELECT press <span class="Special"><C-C></span>t to display a list of tables.<br>
2. Choose a table from the list.<br>
3. Press <span class="Special"><Right></span> to display a list of columns.<br>
4. Choose the column from the list and press enter.<br>
5. Enter a "," and press <span class="Special"><C-C></span>c. Generating a column list<br>
generally requires having the cursor on a table name. The plugin<br>
uses this name to determine what table to retrieve the column list.<br>
In this step, since we are pressing <span class="Special"><C-C></span>c without the cursor<br>
on a table name the column list displayed will be for the previous<br>
table. Choose a different column and move on.<br>
6. Repeat step 5 as often as necessary.<br>
<div class="helpExample"> All columns for a table:</div>
1. After typing SELECT press <span class="Special"><C-C></span>t to display a list of tables.<br>
2. Highlight the table you need the column list for.<br>
3. Press <span class="Special"><Enter></span> to choose the table from the list.<br>
4. Press <span class="Special"><C-C></span>l to request a comma separated list of all columns<br>
for this table.<br>
5. Based on the table name chosen in step 3, the plugin attempts to<br>
decide on a reasonable table alias. You are then prompted to<br>
either accept of change the alias. Press OK.<br>
6. The table name is replaced with the column list of the table is<br>
replaced with the comma separate list of columns with the alias<br>
prepended to each of the columns.<br>
7. Step 3 and 4 can be replaced by pressing <span class="Special"><C-C></span>L, which has<br>
a <span class="Special"><C-Y></span> embedded in the map to choose the currently highlighted<br>
table in the list.<br>
<br>
There is a special provision when writing select statements. Consider the<br>
following statement:<br>
<div class="helpExample"> select *<br>
from customer c,<br>
contact cn,<br>
department as dp,<br>
employee e,<br>
site_options so<br>
where c.</div>
<br>
In INSERT mode after typing the final "c." which is an alias for the<br>
"customer" table, you can press either <span class="Special"><C-C></span>c or <span class="Special"><C-X><C-O></span>. This will<br>
popup a list of columns for the customer table. It does this by looking back<br>
to the beginning of the select statement and finding a list of the tables<br>
specified in the FROM clause. In this case it notes that in the string<br>
"customer c", "c" is an alias for the customer table. The optional "AS"<br>
keyword is also supported, "customer AS c".<br>
<br>
<br>
<div class="helpExample"> 4.3.3 Procedure Completion: *sql-completion-procedures*</div>
<br>
Similar to the table list, <span class="Special"><C-C></span>p, will display a list of stored<br>
procedures stored within the database.<br>
<br>
<div class="helpExample"> 4.3.4 View Completion: *sql-completion-views*</div>
<br>
Similar to the table list, <span class="Special"><C-C></span>v, will display a list of views in the<br>
database.<br>
<br>
<br>
4.4 Completion Customization <a class="Constant" href="ft_sql.html#sql-completion-customization" name="sql-completion-customization">sql-completion-customization</a><br>
<span class="PreProc">----------------------------</span><br>
<br>
The SQL completion plugin can be customized through various options set in<br>
your <a class="Identifier" href="starting.html#vimrc">vimrc</a>:<br>
<div class="helpExample"> omni_sql_no_default_maps</div>
- Default: This variable is not defined<br>
- If this variable is defined, no maps are created for OMNI<br>
completion. See <a class="Identifier" href="ft_sql.html#sql-completion-maps">sql-completion-maps</a> for further discussion.<br>
<br>
<div class="helpExample"> omni_sql_use_tbl_alias</div>
- Default: a<br>
- This setting is only used when generating a comma separated<br>
column list. By default the map is <span class="Special"><C-C></span>l. When generating<br>
a column list, an alias can be prepended to the beginning of each<br>
column, for example: e.emp_id, e.emp_name. This option has three<br>
settings:<br>
<div class="helpExample"> n - do not use an alias<br>
d - use the default (calculated) alias<br>
a - ask to confirm the alias name</div>
<br>
An alias is determined following a few rules:<br>
1. If the table name has an '_', then use it as a separator:<br>
<div class="helpExample"> MY_TABLE_NAME --> MTN<br>
my_table_name --> mtn<br>
My_table_NAME --> MtN</div>
2. If the table name does NOT contain an '_', but DOES use<br>
mixed case then the case is used as a separator:<br>
<div class="helpExample"> MyTableName --> MTN</div>
3. If the table name does NOT contain an '_', and does NOT<br>
use mixed case then the first letter of the table is used:<br>
<div class="helpExample"> mytablename --> m<br>
MYTABLENAME --> M</div>
<br>
<div class="helpExample"> omni_sql_ignorecase</div>
- Default: Current setting for <a class="Type" href="options.html#'ignorecase'">'ignorecase'</a><br>
- Valid settings are 0 or 1.<br>
- When entering a few letters before initiating completion, the list<br>
will be filtered to display only the entries which begin with the<br>
list of characters. When this option is set to 0, the list will be<br>
filtered using case sensitivity.<br>
<br>
<div class="helpExample"> omni_sql_include_owner</div>
- Default: 0, unless dbext.vim 3.00 has been installed<br>
- Valid settings are 0 or 1.<br>
- When completing tables, procedure or views and using dbext.vim 3.00<br>
or higher the list of objects will also include the owner name.<br>
When completing these objects and omni_sql_include_owner is enabled<br>
the owner name will be replaced.<br>
<br>
<div class="helpExample"> omni_sql_precache_syntax_groups</div>
- Default:<br>
[<a class="Type" href="options.html#'syntax'">'syntax'</a>,'sqlKeyword','sqlFunction','sqlOption','sqlType','sqlStatement']<br>
- sqlcomplete can be used in conjunction with other completion<br>
plugins. This is outlined at <a class="Identifier" href="ft_sql.html#sql-completion-filetypes">sql-completion-filetypes</a>. When the<br>
filetype is changed temporarily to SQL, the sqlcompletion plugin<br>
will cache the syntax groups listed in the List specified in this<br>
option.<br>
<br>
<br>
4.5 SQL Maps <a class="Constant" href="ft_sql.html#sql-completion-maps" name="sql-completion-maps">sql-completion-maps</a><br>
<span class="PreProc">------------</span><br>
<br>
The default SQL maps have been described in other sections of this document in<br>
greater detail. Here is a list of the maps with a brief description of each.<br>
<br>
Static Maps<br>
<span class="PreProc">-----------</span><br>
These are maps which use populate the completion list using Vim's syntax<br>
highlighting rules.<br>
<div class="helpExample"> <C-C>a</div>
- Displays all SQL syntax items.<br>
<div class="helpExample"> <C-C>k</div>
- Displays all SQL syntax items defined as 'sqlKeyword'.<br>
<div class="helpExample"> <C-C>f</div>
- Displays all SQL syntax items defined as 'sqlFunction.<br>
<div class="helpExample"> <C-C>o</div>
- Displays all SQL syntax items defined as 'sqlOption'.<br>
<div class="helpExample"> <C-C>T</div>
- Displays all SQL syntax items defined as 'sqlType'.<br>
<div class="helpExample"> <C-C>s</div>
- Displays all SQL syntax items defined as 'sqlStatement'.<br>
<br>
Dynamic Maps<br>
<span class="PreProc">------------</span><br>
These are maps which use populate the completion list using the dbext.vim<br>
plugin.<br>
<div class="helpExample"> <C-C>t</div>
- Displays a list of tables.<br>
<div class="helpExample"> <C-C>p</div>
- Displays a list of procedures.<br>
<div class="helpExample"> <C-C>v</div>
- Displays a list of views.<br>
<div class="helpExample"> <C-C>c</div>
- Displays a list of columns for a specific table.<br>
<div class="helpExample"> <C-C>l</div>
- Displays a comma separated list of columns for a specific table.<br>
<div class="helpExample"> <C-C>L</div>
- Displays a comma separated list of columns for a specific table.<br>
This should only be used when the completion window is active.<br>
<div class="helpExample"> <Right></div>
- Displays a list of columns for the table currently highlighted in<br>
the completion window. <span class="Special"><Right></span> is not recognized on most Unix<br>
systems, so this maps is only created on the Windows platform.<br>
If you would like the same feature on Unix, choose a different key<br>
and make the same map in your vimrc.<br>
<div class="helpExample"> <Left></div>
- Displays the list of tables.<br>
<span class="Special"><Left></span> is not recognized on most Unix systems, so this maps is<br>
only created on the Windows platform. If you would like the same<br>
feature on Unix, choose a different key and make the same map in<br>
your vimrc.<br>
<div class="helpExample"> <C-C>R</div>
- This maps removes all cached items and forces the SQL completion<br>
to regenerate the list of items.<br>
<br>
Customizing Maps<br>
<span class="PreProc">----------------</span><br>
You can create as many additional key maps as you like. Generally, the maps<br>
will be specifying different syntax highlight groups.<br>
<br>
If you do not wish the default maps created or the key choices do not work on<br>
your platform (often a case on *nix) you define the following variable in<br>
your <a class="Identifier" href="starting.html#vimrc">vimrc</a>:<br>
<div class="helpExample"> let g:omni_sql_no_default_maps = 1</div>
<br>
Do no edit ftplugin/sql.vim directly! If you change this file your changes<br>
will be over written on future updates. Vim has a special directory structure<br>
which allows you to make customizations without changing the files that are<br>
included with the Vim distribution. If you wish to customize the maps<br>
create an after/ftplugin/sql.vim (see <a class="Identifier" href="options.html#after-directory">after-directory</a>) and place the same<br>
maps from the ftplugin/sql.vim in it using your own key strokes. <span class="Special"><C-C></span> was<br>
chosen since it will work on both Windows and *nix platforms. On the windows<br>
platform you can also use <span class="Special"><C-Space></span> or ALT keys.<br>
<br>
<br>
4.6 Using with other filetypes <a class="Constant" href="ft_sql.html#sql-completion-filetypes" name="sql-completion-filetypes">sql-completion-filetypes</a><br>
<span class="PreProc">------------------------------</span><br>
<br>
Many times SQL can be used with different filetypes. For example Perl, Java,<br>
PHP, Javascript can all interact with a database. Often you need both the SQL<br>
completion and the completion capabilities for the current language you are<br>
editing.<br>
<br>
This can be enabled easily with the following steps (assuming a Perl file):<br>
<div class="helpExample"> 1. :e test.pl<br>
2. :set filetype=sql<br>
3. :set ft=perl</div>
<br>
Step 1<br>
<span class="PreProc">------</span><br>
Begins by editing a Perl file. Vim automatically sets the filetype to<br>
"perl". By default, Vim runs the appropriate filetype file<br>
ftplugin/perl.vim. If you are using the syntax completion plugin by following<br>
the directions at <a class="Identifier" href="insert.html#ft-syntax-omni">ft-syntax-omni</a> then the <a class="Identifier" href="options.html#'omnifunc'">'omnifunc'</a> option has been set to<br>
"syntax#Complete". Pressing <span class="Special"><C-X><C-O></span> will display the omni popup containing<br>
the syntax items for Perl.<br>
<br>
Step 2<br>
<span class="PreProc">------</span><br>
Manually setting the filetype to <span class="MissingTag">'sql'</span> will also fire the appropriate filetype<br>
files ftplugin/sql.vim. This file will define a number of buffer specific<br>
maps for SQL completion, see <a class="Identifier" href="ft_sql.html#sql-completion-maps">sql-completion-maps</a>. Now these maps have<br>
been created and the SQL completion plugin has been initialized. All SQL<br>
syntax items have been cached in preparation. The SQL filetype script detects<br>
we are attempting to use two different completion plugins. Since the SQL maps<br>
begin with <span class="Special"><C-C></span>, the maps will toggle the <a class="Identifier" href="options.html#'omnifunc'">'omnifunc'</a> when in use. So you<br>
can use <span class="Special"><C-X><C-O></span> to continue using the completion for Perl (using the syntax<br>
completion plugin) and <span class="Special"><C-C></span> to use the SQL completion features.<br>
<br>
Step 3<br>
<span class="PreProc">------</span><br>
Setting the filetype back to Perl sets all the usual "perl" related items back<br>
as they were.<br>
<br>
<br>
vim:tw=78:ts=8:ft=help:norl:<br>
</div>
</article>
<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>
<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->
</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。