sql.vim 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. " SQL filetype plugin file
  2. " Language: SQL (Common for Oracle, Microsoft SQL Server, Sybase)
  3. " Version: 12.0
  4. " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
  5. " Last Change: 2017 Mar 07
  6. " 2024 Jan 14 by Vim Project (browsefilter)
  7. " Download: http://vim.sourceforge.net/script.php?script_id=454
  8. " For more details please use:
  9. " :h sql.txt
  10. "
  11. " This file should only contain values that are common to all SQL languages
  12. " Oracle, Microsoft SQL Server, Sybase ASA/ASE, MySQL, and so on
  13. " If additional features are required create:
  14. " vimfiles/after/ftplugin/sql.vim (Windows)
  15. " .vim/after/ftplugin/sql.vim (Unix)
  16. " to override and add any of your own settings.
  17. " This file also creates a command, SQLSetType, which allows you to change
  18. " SQL dialects on the fly. For example, if I open an Oracle SQL file, it
  19. " is color highlighted appropriately. If I open an Informix SQL file, it
  20. " will still be highlighted according to Oracles settings. By running:
  21. " :SQLSetType sqlinformix
  22. "
  23. " All files called sqlinformix.vim will be loaded from the indent and syntax
  24. " directories. This allows you to easily flip SQL dialects on a per file
  25. " basis. NOTE: you can also use completion:
  26. " :SQLSetType <tab>
  27. "
  28. " To change the default dialect, add the following to your vimrc:
  29. " let g:sql_type_default = 'sqlanywhere'
  30. "
  31. " This file also creates a command, SQLGetType, which allows you to
  32. " determine what the current dialect is in use.
  33. " :SQLGetType
  34. "
  35. " History
  36. "
  37. " Version 12.0 (April 2013)
  38. "
  39. " NF: Added support for "BEGIN TRY ... END TRY ... BEGIN CATCH ... END CATCH
  40. " BF: This plugin is designed to be used with other plugins to enable the
  41. " SQL completion with Perl, Python, Java, ... The loading mechanism
  42. " was not checking if the SQL objects were created, which can lead to
  43. " the plugin not loading the SQL support.
  44. "
  45. " Version 11.0 (May 2013)
  46. "
  47. " NF: Updated to use SyntaxComplete's new regex support for syntax groups.
  48. "
  49. " Version 10.0 (Dec 2012)
  50. "
  51. " NF: Changed all maps to use noremap instead of must map
  52. " NF: Changed all visual maps to use xnoremap instead of vnoremap as they
  53. " should only be used in visual mode and not select mode.
  54. " BF: Most of the maps were using doubled up backslashes before they were
  55. " changed to using the search() function, which meant they no longer
  56. " worked.
  57. "
  58. " Version 9.0
  59. "
  60. " NF: Completes 'b:undo_ftplugin'
  61. " BF: Correctly set cpoptions when creating script
  62. "
  63. " Version 8.0
  64. "
  65. " NF: Improved the matchit plugin regex (Talek)
  66. "
  67. " Version 7.0
  68. "
  69. " NF: Calls the sqlcomplete#ResetCacheSyntax() function when calling
  70. " SQLSetType.
  71. "
  72. " Version 6.0
  73. "
  74. " NF: Adds the command SQLGetType
  75. "
  76. " Version 5.0
  77. "
  78. " NF: Adds the ability to choose the keys to control SQL completion, just add
  79. " the following to your .vimrc:
  80. " let g:ftplugin_sql_omni_key = '<C-C>'
  81. " let g:ftplugin_sql_omni_key_right = '<Right>'
  82. " let g:ftplugin_sql_omni_key_left = '<Left>'
  83. "
  84. " BF: format-options - Auto-wrap comments using textwidth was turned off
  85. " by mistake.
  86. " Only do this when not done yet for this buffer
  87. " This ftplugin can be used with other ftplugins. So ensure loading
  88. " happens if all elements of this plugin have not yet loaded.
  89. if exists("b:did_ftplugin") && exists("b:current_ftplugin") && b:current_ftplugin == 'sql'
  90. finish
  91. endif
  92. let s:save_cpo = &cpo
  93. set cpo&vim
  94. " Disable autowrapping for code, but enable for comments
  95. " t Auto-wrap text using textwidth
  96. " c Auto-wrap comments using textwidth, inserting the current comment
  97. " leader automatically.
  98. setlocal formatoptions-=t
  99. setlocal formatoptions+=c
  100. " Functions/Commands to allow the user to change SQL syntax dialects
  101. " through the use of :SQLSetType <tab> for completion.
  102. " This works with both Vim 6 and 7.
  103. if !exists("*SQL_SetType")
  104. " NOTE: You cannot use function! since this file can be
  105. " sourced from within this function. That will result in
  106. " an error reported by Vim.
  107. function SQL_GetList(ArgLead, CmdLine, CursorPos)
  108. if !exists('s:sql_list')
  109. " Grab a list of files that contain "sql" in their names
  110. let list_indent = globpath(&runtimepath, 'indent/*sql*')
  111. let list_syntax = globpath(&runtimepath, 'syntax/*sql*')
  112. let list_ftplugin = globpath(&runtimepath, 'ftplugin/*sql*')
  113. let sqls = "\n".list_indent."\n".list_syntax."\n".list_ftplugin."\n"
  114. " Strip out everything (path info) but the filename
  115. " Regex
  116. " From between two newline characters
  117. " Non-greedily grab all characters
  118. " Followed by a valid filename \w\+\.\w\+ (sql.vim)
  119. " Followed by a newline, but do not include the newline
  120. "
  121. " Replace it with just the filename (get rid of PATH)
  122. "
  123. " Recursively, since there are many filenames that contain
  124. " the word SQL in the indent, syntax and ftplugin directory
  125. let sqls = substitute( sqls,
  126. \ '[\n]\%(.\{-}\)\(\w\+\.\w\+\)\n\@=',
  127. \ '\1\n',
  128. \ 'g'
  129. \ )
  130. " Remove duplicates, since sqlanywhere.vim can exist in the
  131. " syntax, indent and ftplugin directory, yet we only want
  132. " to display the option once
  133. let index = match(sqls, '.\{-}\ze\n')
  134. while index > -1
  135. " Get the first filename
  136. let file = matchstr(sqls, '.\{-}\ze\n', index)
  137. " Recursively replace any *other* occurrence of that
  138. " filename with nothing (ie remove it)
  139. let sqls = substitute(sqls, '\%>'.(index+strlen(file)).'c\<'.file.'\>\n', '', 'g')
  140. " Move on to the next filename
  141. let index = match(sqls, '.\{-}\ze\n', (index+strlen(file)+1))
  142. endwhile
  143. " Sort the list if using version 7
  144. if v:version >= 700
  145. let mylist = split(sqls, "\n")
  146. let mylist = sort(mylist)
  147. let sqls = join(mylist, "\n")
  148. endif
  149. let s:sql_list = sqls
  150. endif
  151. return s:sql_list
  152. endfunction
  153. function SQL_SetType(name)
  154. " User has decided to override default SQL scripts and
  155. " specify a vendor specific version
  156. " (ie Oracle, Informix, SQL Anywhere, ...)
  157. " So check for an remove any settings that prevent the
  158. " scripts from being executed, and then source the
  159. " appropriate Vim scripts.
  160. if exists("b:did_ftplugin")
  161. unlet b:did_ftplugin
  162. endif
  163. if exists("b:current_syntax")
  164. " echomsg 'SQLSetType - clearing syntax'
  165. syntax clear
  166. if exists("b:current_syntax")
  167. unlet b:current_syntax
  168. endif
  169. endif
  170. if exists("b:did_indent")
  171. " echomsg 'SQLSetType - clearing indent'
  172. unlet b:did_indent
  173. " Set these values to their defaults
  174. setlocal indentkeys&
  175. setlocal indentexpr&
  176. endif
  177. " Ensure the name is in the correct format
  178. let new_sql_type = substitute(a:name,
  179. \ '\s*\([^\.]\+\)\(\.\w\+\)\?', '\L\1', '')
  180. " Do not specify a buffer local variable if it is
  181. " the default value
  182. if new_sql_type == 'sql'
  183. let new_sql_type = 'sqloracle'
  184. endif
  185. let b:sql_type_override = new_sql_type
  186. " Remove any cached SQL since a new syntax will have different
  187. " items and groups
  188. if !exists('g:loaded_sql_completion') || g:loaded_sql_completion >= 100
  189. call sqlcomplete#ResetCacheSyntax()
  190. endif
  191. " Vim will automatically source the correct files if we
  192. " change the filetype. You cannot do this with setfiletype
  193. " since that command will only execute if a filetype has
  194. " not already been set. In this case we want to override
  195. " the existing filetype.
  196. let &filetype = 'sql'
  197. if b:sql_compl_savefunc != ""
  198. " We are changing the filetype to SQL from some other filetype
  199. " which had OMNI completion defined. We need to activate the
  200. " SQL completion plugin in order to cache some of the syntax items
  201. " while the syntax rules for SQL are active.
  202. call sqlcomplete#PreCacheSyntax()
  203. endif
  204. endfunction
  205. command! -nargs=* -complete=custom,SQL_GetList SQLSetType :call SQL_SetType(<q-args>)
  206. endif
  207. " Functions/Commands to allow the user determine current SQL syntax dialect
  208. " This works with both Vim 6 and 7.
  209. if !exists("*SQL_GetType")
  210. function SQL_GetType()
  211. if exists('b:sql_type_override')
  212. echomsg "Current SQL dialect in use:".b:sql_type_override
  213. else
  214. echomsg "Current SQL dialect in use:".g:sql_type_default
  215. endif
  216. endfunction
  217. command! -nargs=0 SQLGetType :call SQL_GetType()
  218. endif
  219. if exists("b:sql_type_override")
  220. " echo 'sourcing buffer ftplugin/'.b:sql_type_override.'.vim'
  221. if globpath(&runtimepath, 'ftplugin/'.b:sql_type_override.'.vim') != ''
  222. exec 'runtime ftplugin/'.b:sql_type_override.'.vim'
  223. " else
  224. " echomsg 'ftplugin/'.b:sql_type_override.' not exist, using default'
  225. endif
  226. elseif exists("g:sql_type_default")
  227. " echo 'sourcing global ftplugin/'.g:sql_type_default.'.vim'
  228. if globpath(&runtimepath, 'ftplugin/'.g:sql_type_default.'.vim') != ''
  229. exec 'runtime ftplugin/'.g:sql_type_default.'.vim'
  230. " else
  231. " echomsg 'ftplugin/'.g:sql_type_default.'.vim not exist, using default'
  232. endif
  233. endif
  234. " If the above runtime command succeeded, do not load the default settings
  235. " as they should have already been loaded from a previous run.
  236. if exists("b:did_ftplugin") && exists("b:current_ftplugin") && b:current_ftplugin == 'sql'
  237. finish
  238. endif
  239. let b:undo_ftplugin = "setl comments< formatoptions< define< omnifunc<" .
  240. \ " | unlet! b:browsefilter b:match_words"
  241. " Don't load another plugin for this buffer
  242. let b:did_ftplugin = 1
  243. let b:current_ftplugin = 'sql'
  244. " Win32 and GTK can filter files in the browse dialog
  245. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  246. let b:browsefilter = "SQL Files (*.sql)\t*.sql\n"
  247. if has("win32")
  248. let b:browsefilter .= "All Files (*.*)\t*\n"
  249. else
  250. let b:browsefilter .= "All Files (*)\t*\n"
  251. endif
  252. endif
  253. " Some standard expressions for use with the matchit strings
  254. let s:notend = '\%(\<end\s\+\)\@<!'
  255. let s:when_no_matched_or_others = '\%(\<when\>\%(\s\+\%(\%(\<not\>\s\+\)\?<matched\>\)\|\<others\>\)\@!\)'
  256. let s:or_replace = '\%(or\s\+replace\s\+\)\?'
  257. " Define patterns for the matchit macro
  258. if !exists("b:match_words")
  259. " SQL is generally case insensitive
  260. let b:match_ignorecase = 1
  261. " Handle the following:
  262. " if
  263. " elseif | elsif
  264. " else [if]
  265. " end if
  266. "
  267. " [while condition] loop
  268. " leave
  269. " break
  270. " continue
  271. " exit
  272. " end loop
  273. "
  274. " for
  275. " leave
  276. " break
  277. " continue
  278. " exit
  279. " end loop
  280. "
  281. " do
  282. " statements
  283. " doend
  284. "
  285. " case
  286. " when
  287. " when
  288. " default
  289. " end case
  290. "
  291. " merge
  292. " when not matched
  293. " when matched
  294. "
  295. " EXCEPTION
  296. " WHEN column_not_found THEN
  297. " WHEN OTHERS THEN
  298. "
  299. " begin try
  300. " end try
  301. " begin catch
  302. " end catch
  303. "
  304. " create[ or replace] procedure|function|event
  305. " \ '^\s*\<\%(do\|for\|while\|loop\)\>.*:'.
  306. " For ColdFusion support
  307. setlocal matchpairs+=<:>
  308. let b:match_words = &matchpairs .
  309. \ ',\%(\<begin\)\%(\s\+\%(try\|catch\)\>\)\@!:\<end\>\W*$,'.
  310. \
  311. \ '\<begin\s\+try\>:'.
  312. \ '\<end\s\+try\>:'.
  313. \ '\<begin\s\+catch\>:'.
  314. \ '\<end\s\+catch\>,'.
  315. \
  316. \ s:notend . '\<if\>:'.
  317. \ '\<elsif\>\|\<elseif\>\|\<else\>:'.
  318. \ '\<end\s\+if\>,'.
  319. \
  320. \ '\(^\s*\)\@<=\(\<\%(do\|for\|while\|loop\)\>.*\):'.
  321. \ '\%(\<exit\>\|\<leave\>\|\<break\>\|\<continue\>\):'.
  322. \ '\%(\<doend\>\|\%(\<end\s\+\%(for\|while\|loop\>\)\)\),'.
  323. \
  324. \ '\%('. s:notend . '\<case\>\):'.
  325. \ '\%('.s:when_no_matched_or_others.'\):'.
  326. \ '\%(\<when\s\+others\>\|\<end\s\+case\>\),' .
  327. \
  328. \ '\<merge\>:' .
  329. \ '\<when\s\+not\s\+matched\>:' .
  330. \ '\<when\s\+matched\>,' .
  331. \
  332. \ '\%(\<create\s\+' . s:or_replace . '\)\?'.
  333. \ '\%(function\|procedure\|event\):'.
  334. \ '\<returns\?\>'
  335. " \ '\<begin\>\|\<returns\?\>:'.
  336. " \ '\<end\>\(;\)\?\s*$'
  337. " \ '\<exception\>:'.s:when_no_matched_or_others.
  338. " \ ':\<when\s\+others\>,'.
  339. "
  340. " \ '\%(\<exception\>\|\%('. s:notend . '\<case\>\)\):'.
  341. " \ '\%(\<default\>\|'.s:when_no_matched_or_others.'\):'.
  342. " \ '\%(\%(\<when\s\+others\>\)\|\<end\s\+case\>\),' .
  343. endif
  344. " Define how to find the macro definition of a variable using the various
  345. " [d, [D, [_CTRL_D and so on features
  346. " Match these values ignoring case
  347. " ie DECLARE varname INTEGER
  348. let &l:define = '\c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>'
  349. " Mappings to move to the next BEGIN ... END block
  350. " \W - no characters or digits
  351. nnoremap <buffer> <silent> ]] :call search('\c^\s*begin\>', 'W' )<CR>
  352. nnoremap <buffer> <silent> [[ :call search('\c^\s*begin\>', 'bW' )<CR>
  353. nnoremap <buffer> <silent> ][ :call search('\c^\s*end\W*$', 'W' )<CR>
  354. nnoremap <buffer> <silent> [] :call search('\c^\s*end\W*$', 'bW' )<CR>
  355. xnoremap <buffer> <silent> ]] :<C-U>exec "normal! gv"<Bar>call search('\c^\s*begin\>', 'W' )<CR>
  356. xnoremap <buffer> <silent> [[ :<C-U>exec "normal! gv"<Bar>call search('\c^\s*begin\>', 'bW' )<CR>
  357. xnoremap <buffer> <silent> ][ :<C-U>exec "normal! gv"<Bar>call search('\c^\s*end\W*$', 'W' )<CR>
  358. xnoremap <buffer> <silent> [] :<C-U>exec "normal! gv"<Bar>call search('\c^\s*end\W*$', 'bW' )<CR>
  359. " By default only look for CREATE statements, but allow
  360. " the user to override
  361. if !exists('g:ftplugin_sql_statements')
  362. let g:ftplugin_sql_statements = 'create'
  363. endif
  364. " Predefined SQL objects what are used by the below mappings using
  365. " the ]} style maps.
  366. " This global variable allows the users to override its value
  367. " from within their vimrc.
  368. " Note, you cannot use \?, since these patterns can be used to search
  369. " backwards, you must use \{,1}
  370. if !exists('g:ftplugin_sql_objects')
  371. let g:ftplugin_sql_objects = 'function,procedure,event,' .
  372. \ '\(existing\\|global\s\+temporary\s\+\)\{,1}' .
  373. \ 'table,trigger' .
  374. \ ',schema,service,publication,database,datatype,domain' .
  375. \ ',index,subscription,synchronization,view,variable'
  376. endif
  377. " Key to trigger SQL completion
  378. if !exists('g:ftplugin_sql_omni_key')
  379. let g:ftplugin_sql_omni_key = '<C-C>'
  380. endif
  381. " Key to trigger drill into column list
  382. if !exists('g:ftplugin_sql_omni_key_right')
  383. let g:ftplugin_sql_omni_key_right = '<Right>'
  384. endif
  385. " Key to trigger drill out of column list
  386. if !exists('g:ftplugin_sql_omni_key_left')
  387. let g:ftplugin_sql_omni_key_left = '<Left>'
  388. endif
  389. " Replace all ,'s with bars, except ones with numbers after them.
  390. " This will most likely be a \{,1} string.
  391. let s:ftplugin_sql_objects =
  392. \ '\c^\s*' .
  393. \ '\(\(' .
  394. \ substitute(g:ftplugin_sql_statements, ',\d\@!', '\\\\|', 'g') .
  395. \ '\)\s\+\(or\s\+replace\s\+\)\{,1}\)\{,1}' .
  396. \ '\<\(' .
  397. \ substitute(g:ftplugin_sql_objects, ',\d\@!', '\\\\|', 'g') .
  398. \ '\)\>'
  399. " Mappings to move to the next CREATE ... block
  400. exec "nnoremap <buffer> <silent> ]} :call search('".s:ftplugin_sql_objects."', 'W')<CR>"
  401. exec "nnoremap <buffer> <silent> [{ :call search('".s:ftplugin_sql_objects."', 'bW')<CR>"
  402. " Could not figure out how to use a :call search() string in visual mode
  403. " without it ending visual mode
  404. " Unfortunately, this will add a entry to the search history
  405. exec 'xnoremap <buffer> <silent> ]} /'.s:ftplugin_sql_objects.'<CR>'
  406. exec 'xnoremap <buffer> <silent> [{ ?'.s:ftplugin_sql_objects.'<CR>'
  407. " Mappings to move to the next COMMENT
  408. "
  409. " Had to double the \ for the \| separator since this has a special
  410. " meaning on maps
  411. let b:comment_leader = '\(--\\|\/\/\\|\*\\|\/\*\\|\*\/\)'
  412. " Find the start of the next comment
  413. let b:comment_start = '^\(\s*'.b:comment_leader.'.*\n\)\@<!'.
  414. \ '\(\s*'.b:comment_leader.'\)'
  415. " Find the end of the previous comment
  416. let b:comment_end = '\(^\s*'.b:comment_leader.'.*\n\)'.
  417. \ '\(^\s*'.b:comment_leader.'\)\@!'
  418. " Skip over the comment
  419. let b:comment_jump_over = "call search('".
  420. \ '^\(\s*'.b:comment_leader.'.*\n\)\@<!'.
  421. \ "', 'W')"
  422. let b:comment_skip_back = "call search('".
  423. \ '^\(\s*'.b:comment_leader.'.*\n\)\@<!'.
  424. \ "', 'bW')"
  425. " Move to the start and end of comments
  426. exec 'nnoremap <silent><buffer> ]" :call search('."'".b:comment_start."'".', "W" )<CR>'
  427. exec 'nnoremap <silent><buffer> [" :call search('."'".b:comment_end."'".', "W" )<CR>'
  428. exec 'xnoremap <silent><buffer> ]" :<C-U>exec "normal! gv"<Bar>call search('."'".b:comment_start."'".', "W" )<CR>'
  429. exec 'xnoremap <silent><buffer> [" :<C-U>exec "normal! gv"<Bar>call search('."'".b:comment_end."'".', "W" )<CR>'
  430. " Comments can be of the form:
  431. " /*
  432. " *
  433. " */
  434. " or
  435. " --
  436. " or
  437. " //
  438. setlocal comments=s1:/*,mb:*,ex:*/,:--,://
  439. " Set completion with CTRL-X CTRL-O to autoloaded function.
  440. if exists('&omnifunc')
  441. " Since the SQL completion plugin can be used in conjunction
  442. " with other completion filetypes it must record the previous
  443. " OMNI function prior to setting up the SQL OMNI function
  444. let b:sql_compl_savefunc = &omnifunc
  445. " Source it to determine its version
  446. runtime autoload/sqlcomplete.vim
  447. " This is used by the sqlcomplete.vim plugin
  448. " Source it for its global functions
  449. runtime autoload/syntaxcomplete.vim
  450. setlocal omnifunc=sqlcomplete#Complete
  451. " Prevent the intellisense plugin from loading
  452. let b:sql_vis = 1
  453. if !exists('g:omni_sql_no_default_maps')
  454. let regex_extra = ''
  455. if exists('g:loaded_syntax_completion') && exists('g:loaded_sql_completion')
  456. if g:loaded_syntax_completion > 120 && g:loaded_sql_completion > 140
  457. let regex_extra = '\\w*'
  458. endif
  459. endif
  460. " Static maps which use populate the completion list
  461. " using Vim's syntax highlighting rules
  462. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'a <C-\><C-O>:call sqlcomplete#Map("syntax")<CR><C-X><C-O>'
  463. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'k <C-\><C-O>:call sqlcomplete#Map("sqlKeyword'.regex_extra.'")<CR><C-X><C-O>'
  464. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'f <C-\><C-O>:call sqlcomplete#Map("sqlFunction'.regex_extra.'")<CR><C-X><C-O>'
  465. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'o <C-\><C-O>:call sqlcomplete#Map("sqlOption'.regex_extra.'")<CR><C-X><C-O>'
  466. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'T <C-\><C-O>:call sqlcomplete#Map("sqlType'.regex_extra.'")<CR><C-X><C-O>'
  467. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'s <C-\><C-O>:call sqlcomplete#Map("sqlStatement'.regex_extra.'")<CR><C-X><C-O>'
  468. " Dynamic maps which use populate the completion list
  469. " using the dbext.vim plugin
  470. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'t <C-\><C-O>:call sqlcomplete#Map("table")<CR><C-X><C-O>'
  471. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'p <C-\><C-O>:call sqlcomplete#Map("procedure")<CR><C-X><C-O>'
  472. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'v <C-\><C-O>:call sqlcomplete#Map("view")<CR><C-X><C-O>'
  473. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'c <C-\><C-O>:call sqlcomplete#Map("column")<CR><C-X><C-O>'
  474. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'l <C-\><C-O>:call sqlcomplete#Map("column_csv")<CR><C-X><C-O>'
  475. " The next 3 maps are only to be used while the completion window is
  476. " active due to the <CR> at the beginning of the map
  477. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'L <C-Y><C-\><C-O>:call sqlcomplete#Map("column_csv")<CR><C-X><C-O>'
  478. " <C-Right> is not recognized on most Unix systems, so only create
  479. " these additional maps on the Windows platform.
  480. " If you would like to use these maps, choose a different key and make
  481. " the same map in your vimrc.
  482. " if has('win32')
  483. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key_right.' <C-R>=sqlcomplete#DrillIntoTable()<CR>'
  484. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key_left.' <C-R>=sqlcomplete#DrillOutOfColumns()<CR>'
  485. " endif
  486. " Remove any cached items useful for schema changes
  487. exec 'inoremap <buffer> '.g:ftplugin_sql_omni_key.'R <C-\><C-O>:call sqlcomplete#Map("resetCache")<CR><C-X><C-O>'
  488. endif
  489. if b:sql_compl_savefunc != ""
  490. " We are changing the filetype to SQL from some other filetype
  491. " which had OMNI completion defined. We need to activate the
  492. " SQL completion plugin in order to cache some of the syntax items
  493. " while the syntax rules for SQL are active.
  494. call sqlcomplete#ResetCacheSyntax()
  495. call sqlcomplete#PreCacheSyntax()
  496. endif
  497. endif
  498. let &cpo = s:save_cpo
  499. unlet s:save_cpo
  500. " vim:sw=4: