sql.vim 21 KB

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