sql.vim 21 KB

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