Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 1 | " SQL filetype plugin file |
| 2 | " Language: SQL (Common for Oracle, Microsoft SQL Server, Sybase) |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 3 | " Version: 4.0 |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 4 | " Maintainer: David Fishburn <fishburn at ianywhere dot com> |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 5 | " Last Change: Wed 27 Feb 2008 04:35:21 PM Eastern Standard Time |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 6 | " Download: http://vim.sourceforge.net/script.php?script_id=454 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 8 | " For more details please use: |
| 9 | " :h sql.txt |
| 10 | " |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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: |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 14 | " vimfiles/after/ftplugin/sql.vim (Windows) |
| 15 | " .vim/after/ftplugin/sql.vim (Unix) |
| 16 | " to override and add any of your own settings. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 18 | |
| 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | " Only do this when not done yet for this buffer |
| 35 | if exists("b:did_ftplugin") |
| 36 | finish |
| 37 | endif |
| 38 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 39 | let s:save_cpo = &cpo |
| 40 | set cpo= |
| 41 | |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 42 | " Disable autowrapping for code, but enable for comments |
| 43 | " t Auto-wrap text using textwidth |
| 44 | " c Auto-wrap comments using textwidth, inserting the current comment |
| 45 | " leader automatically. |
| 46 | setlocal formatoptions-=t |
| 47 | setlocal formatoptions-=c |
| 48 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 49 | " Functions/Commands to allow the user to change SQL syntax dialects |
| 50 | " through the use of :SQLSetType <tab> for completion. |
| 51 | " This works with both Vim 6 and 7. |
| 52 | |
| 53 | if !exists("*SQL_SetType") |
| 54 | " NOTE: You cannot use function! since this file can be |
| 55 | " sourced from within this function. That will result in |
| 56 | " an error reported by Vim. |
| 57 | function SQL_GetList(ArgLead, CmdLine, CursorPos) |
| 58 | |
| 59 | if !exists('s:sql_list') |
| 60 | " Grab a list of files that contain "sql" in their names |
| 61 | let list_indent = globpath(&runtimepath, 'indent/*sql*') |
| 62 | let list_syntax = globpath(&runtimepath, 'syntax/*sql*') |
| 63 | let list_ftplugin = globpath(&runtimepath, 'ftplugin/*sql*') |
| 64 | |
| 65 | let sqls = "\n".list_indent."\n".list_syntax."\n".list_ftplugin."\n" |
| 66 | |
| 67 | " Strip out everything (path info) but the filename |
| 68 | " Regex |
| 69 | " From between two newline characters |
| 70 | " Non-greedily grab all characters |
| 71 | " Followed by a valid filename \w\+\.\w\+ (sql.vim) |
| 72 | " Followed by a newline, but do not include the newline |
| 73 | " |
| 74 | " Replace it with just the filename (get rid of PATH) |
| 75 | " |
| 76 | " Recursively, since there are many filenames that contain |
| 77 | " the word SQL in the indent, syntax and ftplugin directory |
| 78 | let sqls = substitute( sqls, |
| 79 | \ '[\n]\%(.\{-}\)\(\w\+\.\w\+\)\n\@=', |
| 80 | \ '\1\n', |
| 81 | \ 'g' |
| 82 | \ ) |
| 83 | |
| 84 | " Remove duplicates, since sqlanywhere.vim can exist in the |
| 85 | " sytax, indent and ftplugin directory, yet we only want |
| 86 | " to display the option once |
| 87 | let index = match(sqls, '.\{-}\ze\n') |
| 88 | while index > -1 |
| 89 | " Get the first filename |
| 90 | let file = matchstr(sqls, '.\{-}\ze\n', index) |
| 91 | " Recursively replace any *other* occurrence of that |
| 92 | " filename with nothing (ie remove it) |
| 93 | let sqls = substitute(sqls, '\%>'.(index+strlen(file)).'c\<'.file.'\>\n', '', 'g') |
| 94 | " Move on to the next filename |
| 95 | let index = match(sqls, '.\{-}\ze\n', (index+strlen(file)+1)) |
| 96 | endwhile |
| 97 | |
| 98 | " Sort the list if using version 7 |
| 99 | if v:version >= 700 |
| 100 | let mylist = split(sqls, "\n") |
| 101 | let mylist = sort(mylist) |
| 102 | let sqls = join(mylist, "\n") |
| 103 | endif |
| 104 | |
| 105 | let s:sql_list = sqls |
| 106 | endif |
| 107 | |
| 108 | return s:sql_list |
| 109 | |
| 110 | endfunction |
| 111 | |
| 112 | function SQL_SetType(name) |
| 113 | |
| 114 | " User has decided to override default SQL scripts and |
| 115 | " specify a vendor specific version |
| 116 | " (ie Oracle, Informix, SQL Anywhere, ...) |
| 117 | " So check for an remove any settings that prevent the |
| 118 | " scripts from being executed, and then source the |
| 119 | " appropriate Vim scripts. |
| 120 | if exists("b:did_ftplugin") |
| 121 | unlet b:did_ftplugin |
| 122 | endif |
| 123 | if exists("b:current_syntax") |
| 124 | " echomsg 'SQLSetType - clearing syntax' |
| 125 | syntax clear |
| 126 | endif |
| 127 | if exists("b:did_indent") |
| 128 | " echomsg 'SQLSetType - clearing indent' |
| 129 | unlet b:did_indent |
| 130 | " Set these values to their defaults |
| 131 | setlocal indentkeys& |
| 132 | setlocal indentexpr& |
| 133 | endif |
| 134 | |
| 135 | " Ensure the name is in the correct format |
| 136 | let new_sql_type = substitute(a:name, |
| 137 | \ '\s*\([^\.]\+\)\(\.\w\+\)\?', '\L\1', '') |
| 138 | |
| 139 | " Do not specify a buffer local variable if it is |
| 140 | " the default value |
| 141 | if new_sql_type == 'sql' |
| 142 | let new_sql_type = 'sqloracle' |
| 143 | endif |
| 144 | let b:sql_type_override = new_sql_type |
| 145 | |
| 146 | " Vim will automatically source the correct files if we |
| 147 | " change the filetype. You cannot do this with setfiletype |
| 148 | " since that command will only execute if a filetype has |
| 149 | " not already been set. In this case we want to override |
| 150 | " the existing filetype. |
| 151 | let &filetype = 'sql' |
| 152 | endfunction |
| 153 | command! -nargs=* -complete=custom,SQL_GetList SQLSetType :call SQL_SetType(<q-args>) |
| 154 | |
| 155 | endif |
| 156 | |
| 157 | if exists("b:sql_type_override") |
| 158 | " echo 'sourcing buffer ftplugin/'.b:sql_type_override.'.vim' |
| 159 | if globpath(&runtimepath, 'ftplugin/'.b:sql_type_override.'.vim') != '' |
| 160 | exec 'runtime ftplugin/'.b:sql_type_override.'.vim' |
| 161 | " else |
| 162 | " echomsg 'ftplugin/'.b:sql_type_override.' not exist, using default' |
| 163 | endif |
| 164 | elseif exists("g:sql_type_default") |
| 165 | " echo 'sourcing global ftplugin/'.g:sql_type_default.'.vim' |
| 166 | if globpath(&runtimepath, 'ftplugin/'.g:sql_type_default.'.vim') != '' |
| 167 | exec 'runtime ftplugin/'.g:sql_type_default.'.vim' |
| 168 | " else |
| 169 | " echomsg 'ftplugin/'.g:sql_type_default.'.vim not exist, using default' |
| 170 | endif |
| 171 | endif |
| 172 | |
| 173 | " If the above runtime command succeeded, do not load the default settings |
| 174 | if exists("b:did_ftplugin") |
| 175 | finish |
| 176 | endif |
| 177 | |
| 178 | let b:undo_ftplugin = "setl comments<" |
| 179 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 180 | " Don't load another plugin for this buffer |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 181 | let b:did_ftplugin = 1 |
| 182 | let b:current_ftplugin = 'sql' |
| 183 | |
| 184 | " Win32 can filter files in the browse dialog |
| 185 | if has("gui_win32") && !exists("b:browsefilter") |
| 186 | let b:browsefilter = "SQL Files (*.sql)\t*.sql\n" . |
| 187 | \ "All Files (*.*)\t*.*\n" |
| 188 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 189 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 190 | " Some standard expressions for use with the matchit strings |
| 191 | let s:notend = '\%(\<end\s\+\)\@<!' |
| 192 | let s:when_no_matched_or_others = '\%(\<when\>\%(\s\+\%(\%(\<not\>\s\+\)\?<matched\>\)\|\<others\>\)\@!\)' |
| 193 | let s:or_replace = '\%(or\s\+replace\s\+\)\?' |
| 194 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 195 | " Define patterns for the matchit macro |
| 196 | if !exists("b:match_words") |
| 197 | " SQL is generally case insensitive |
| 198 | let b:match_ignorecase = 1 |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 199 | |
| 200 | " Handle the following: |
| 201 | " if |
| 202 | " elseif | elsif |
| 203 | " else [if] |
| 204 | " end if |
| 205 | " |
| 206 | " [while condition] loop |
| 207 | " leave |
| 208 | " break |
| 209 | " continue |
| 210 | " exit |
| 211 | " end loop |
| 212 | " |
| 213 | " for |
| 214 | " leave |
| 215 | " break |
| 216 | " continue |
| 217 | " exit |
| 218 | " end loop |
| 219 | " |
| 220 | " do |
| 221 | " statements |
| 222 | " doend |
| 223 | " |
| 224 | " case |
| 225 | " when |
| 226 | " when |
| 227 | " default |
| 228 | " end case |
| 229 | " |
| 230 | " merge |
| 231 | " when not matched |
| 232 | " when matched |
| 233 | " |
| 234 | " EXCEPTION |
| 235 | " WHEN column_not_found THEN |
| 236 | " WHEN OTHERS THEN |
| 237 | " |
| 238 | " create[ or replace] procedure|function|event |
| 239 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 240 | let b:match_words = |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 241 | \ '\<begin\>:\<end\>\W*$,'. |
| 242 | \ |
| 243 | \ s:notend . '\<if\>:'. |
| 244 | \ '\<elsif\>\|\<elseif\>\|\<else\>:'. |
| 245 | \ '\<end\s\+if\>,'. |
| 246 | \ |
| 247 | \ '\<do\>\|'. |
| 248 | \ '\<while\>\|'. |
| 249 | \ '\%(' . s:notend . '\<loop\>\)\|'. |
| 250 | \ '\%(' . s:notend . '\<for\>\):'. |
| 251 | \ '\<exit\>\|\<leave\>\|\<break\>\|\<continue\>:'. |
| 252 | \ '\%(\<end\s\+\%(for\|loop\>\)\)\|\<doend\>,'. |
| 253 | \ |
| 254 | \ '\%('. s:notend . '\<case\>\):'. |
| 255 | \ '\%('.s:when_no_matched_or_others.'\):'. |
| 256 | \ '\%(\<when\s\+others\>\|\<end\s\+case\>\),' . |
| 257 | \ |
| 258 | \ '\<merge\>:' . |
| 259 | \ '\<when\s\+not\s\+matched\>:' . |
| 260 | \ '\<when\s\+matched\>,' . |
| 261 | \ |
| 262 | \ '\%(\<create\s\+' . s:or_replace . '\)\?'. |
| 263 | \ '\%(function\|procedure\|event\):'. |
| 264 | \ '\<returns\?\>' |
| 265 | " \ '\<begin\>\|\<returns\?\>:'. |
| 266 | " \ '\<end\>\(;\)\?\s*$' |
| 267 | " \ '\<exception\>:'.s:when_no_matched_or_others. |
| 268 | " \ ':\<when\s\+others\>,'. |
| 269 | " |
| 270 | " \ '\%(\<exception\>\|\%('. s:notend . '\<case\>\)\):'. |
| 271 | " \ '\%(\<default\>\|'.s:when_no_matched_or_others.'\):'. |
| 272 | " \ '\%(\%(\<when\s\+others\>\)\|\<end\s\+case\>\),' . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 273 | endif |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 274 | |
| 275 | " Define how to find the macro definition of a variable using the various |
| 276 | " [d, [D, [_CTRL_D and so on features |
| 277 | " Match these values ignoring case |
| 278 | " ie DECLARE varname INTEGER |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 279 | let &l:define = '\c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 280 | |
| 281 | |
| 282 | " Mappings to move to the next BEGIN ... END block |
| 283 | " \W - no characters or digits |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 284 | nmap <buffer> <silent> ]] :call search('\\c^\\s*begin\\>', 'W' )<CR> |
| 285 | nmap <buffer> <silent> [[ :call search('\\c^\\s*begin\\>', 'bW' )<CR> |
| 286 | nmap <buffer> <silent> ][ :call search('\\c^\\s*end\\W*$', 'W' )<CR> |
| 287 | nmap <buffer> <silent> [] :call search('\\c^\\s*end\\W*$', 'bW' )<CR> |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 288 | vmap <buffer> <silent> ]] :<C-U>exec "normal! gv"<Bar>call search('\\c^\\s*begin\\>', 'W' )<CR> |
| 289 | vmap <buffer> <silent> [[ :<C-U>exec "normal! gv"<Bar>call search('\\c^\\s*begin\\>', 'bW' )<CR> |
| 290 | vmap <buffer> <silent> ][ :<C-U>exec "normal! gv"<Bar>call search('\\c^\\s*end\\W*$', 'W' )<CR> |
| 291 | vmap <buffer> <silent> [] :<C-U>exec "normal! gv"<Bar>call search('\\c^\\s*end\\W*$', 'bW' )<CR> |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 292 | |
| 293 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 294 | " By default only look for CREATE statements, but allow |
| 295 | " the user to override |
| 296 | if !exists('g:ftplugin_sql_statements') |
| 297 | let g:ftplugin_sql_statements = 'create' |
| 298 | endif |
| 299 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 300 | " Predefined SQL objects what are used by the below mappings using |
| 301 | " the ]} style maps. |
| 302 | " This global variable allows the users to override it's value |
| 303 | " from within their vimrc. |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 304 | " Note, you cannot use \?, since these patterns can be used to search |
| 305 | " backwards, you must use \{,1} |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 306 | if !exists('g:ftplugin_sql_objects') |
| 307 | let g:ftplugin_sql_objects = 'function,procedure,event,' . |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 308 | \ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' . |
| 309 | \ 'table,trigger' . |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 310 | \ ',schema,service,publication,database,datatype,domain' . |
| 311 | \ ',index,subscription,synchronization,view,variable' |
| 312 | endif |
| 313 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 314 | " Replace all ,'s with bars, except ones with numbers after them. |
| 315 | " This will most likely be a \{,1} string. |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 316 | let s:ftplugin_sql_objects = |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 317 | \ '\\c^\\s*' . |
| 318 | \ '\\(\\(' . |
| 319 | \ substitute(g:ftplugin_sql_statements, ',\d\@!', '\\\\\\|', 'g') . |
| 320 | \ '\\)\\s\\+\\(or\\s\\+replace\\\s\+\\)\\{,1}\\)\\{,1}' . |
| 321 | \ '\\<\\(' . |
| 322 | \ substitute(g:ftplugin_sql_objects, ',\d\@!', '\\\\\\|', 'g') . |
| 323 | \ '\\)\\>' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 324 | |
| 325 | " Mappings to move to the next CREATE ... block |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 326 | exec "nmap <buffer> <silent> ]} :call search('".s:ftplugin_sql_objects."', 'W')<CR>" |
| 327 | exec "nmap <buffer> <silent> [{ :call search('".s:ftplugin_sql_objects."', 'bW')<CR>" |
| 328 | " Could not figure out how to use a :call search() string in visual mode |
| 329 | " without it ending visual mode |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 330 | " Unfortunately, this will add a entry to the search history |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 331 | exec 'vmap <buffer> <silent> ]} /'.s:ftplugin_sql_objects.'<CR>' |
| 332 | exec 'vmap <buffer> <silent> [{ ?'.s:ftplugin_sql_objects.'<CR>' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 333 | |
| 334 | " Mappings to move to the next COMMENT |
| 335 | " |
| 336 | " Had to double the \ for the \| separator since this has a special |
| 337 | " meaning on maps |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 338 | let b:comment_leader = '\\(--\\\|\\/\\/\\\|\\*\\\|\\/\\*\\\|\\*\\/\\)' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 339 | " Find the start of the next comment |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 340 | let b:comment_start = '^\\(\\s*'.b:comment_leader.'.*\\n\\)\\@<!'. |
| 341 | \ '\\(\\s*'.b:comment_leader.'\\)' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 342 | " Find the end of the previous comment |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 343 | let b:comment_end = '\\(^\\s*'.b:comment_leader.'.*\\n\\)'. |
| 344 | \ '\\(^\\s*'.b:comment_leader.'\\)\\@!' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 345 | " Skip over the comment |
| 346 | let b:comment_jump_over = "call search('". |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 347 | \ '^\\(\\s*'.b:comment_leader.'.*\\n\\)\\@<!'. |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 348 | \ "', 'W')" |
| 349 | let b:comment_skip_back = "call search('". |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 350 | \ '^\\(\\s*'.b:comment_leader.'.*\\n\\)\\@<!'. |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 351 | \ "', 'bW')" |
| 352 | " Move to the start and end of comments |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 353 | exec 'nnoremap <silent><buffer> ]" :call search('."'".b:comment_start."'".', "W" )<CR>' |
| 354 | exec 'nnoremap <silent><buffer> [" :call search('."'".b:comment_end."'".', "W" )<CR>' |
| 355 | exec 'vnoremap <silent><buffer> ]" :<C-U>exec "normal! gv"<Bar>call search('."'".b:comment_start."'".', "W" )<CR>' |
| 356 | exec 'vnoremap <silent><buffer> [" :<C-U>exec "normal! gv"<Bar>call search('."'".b:comment_end."'".', "W" )<CR>' |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 357 | |
| 358 | " Comments can be of the form: |
| 359 | " /* |
| 360 | " * |
| 361 | " */ |
| 362 | " or |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 363 | " -- |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 364 | " or |
| 365 | " // |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 366 | setlocal comments=s1:/*,mb:*,ex:*/,:--,:// |
| 367 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 368 | " Set completion with CTRL-X CTRL-O to autoloaded function. |
| 369 | if exists('&omnifunc') |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 370 | " Since the SQL completion plugin can be used in conjunction |
| 371 | " with other completion filetypes it must record the previous |
| 372 | " OMNI function prior to setting up the SQL OMNI function |
| 373 | let b:sql_compl_savefunc = &omnifunc |
| 374 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 375 | " This is used by the sqlcomplete.vim plugin |
| 376 | " Source it for it's global functions |
| 377 | runtime autoload/syntaxcomplete.vim |
| 378 | |
| 379 | setlocal omnifunc=sqlcomplete#Complete |
| 380 | " Prevent the intellisense plugin from loading |
| 381 | let b:sql_vis = 1 |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 382 | if !exists('g:omni_sql_no_default_maps') |
| 383 | " Static maps which use populate the completion list |
| 384 | " using Vim's syntax highlighting rules |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 385 | imap <buffer> <c-c>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O> |
| 386 | imap <buffer> <c-c>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> |
| 387 | imap <buffer> <c-c>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O> |
| 388 | imap <buffer> <c-c>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O> |
| 389 | imap <buffer> <c-c>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O> |
| 390 | imap <buffer> <c-c>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O> |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 391 | " Dynamic maps which use populate the completion list |
| 392 | " using the dbext.vim plugin |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 393 | imap <buffer> <c-c>t <C-\><C-O>:call sqlcomplete#Map('table')<CR><C-X><C-O> |
| 394 | imap <buffer> <c-c>p <C-\><C-O>:call sqlcomplete#Map('procedure')<CR><C-X><C-O> |
| 395 | imap <buffer> <c-c>v <C-\><C-O>:call sqlcomplete#Map('view')<CR><C-X><C-O> |
| 396 | imap <buffer> <c-c>c <C-\><C-O>:call sqlcomplete#Map('column')<CR><C-X><C-O> |
| 397 | imap <buffer> <c-c>l <C-\><C-O>:call sqlcomplete#Map('column_csv')<CR><C-X><C-O> |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 398 | " The next 3 maps are only to be used while the completion window is |
| 399 | " active due to the <CR> at the beginning of the map |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 400 | imap <buffer> <c-c>L <C-Y><C-\><C-O>:call sqlcomplete#Map('column_csv')<CR><C-X><C-O> |
| 401 | " <C-Right> is not recognized on most Unix systems, so only create |
| 402 | " these additional maps on the Windows platform. |
| 403 | " If you would like to use these maps, choose a different key and make |
| 404 | " the same map in your vimrc. |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 405 | if has('win32') |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 406 | imap <buffer> <c-right> <C-R>=sqlcomplete#DrillIntoTable()<CR> |
| 407 | imap <buffer> <c-left> <C-R>=sqlcomplete#DrillOutOfColumns()<CR> |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 408 | endif |
| 409 | " Remove any cached items useful for schema changes |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 410 | imap <buffer> <c-c>R <C-\><C-O>:call sqlcomplete#Map('resetCache')<CR><C-X><C-O> |
| 411 | endif |
| 412 | |
| 413 | if b:sql_compl_savefunc != "" |
| 414 | " We are changing the filetype to SQL from some other filetype |
| 415 | " which had OMNI completion defined. We need to activate the |
| 416 | " SQL completion plugin in order to cache some of the syntax items |
| 417 | " while the syntax rules for SQL are active. |
| 418 | call sqlcomplete#PreCacheSyntax() |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 419 | endif |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 420 | endif |
| 421 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 422 | let &cpo = s:save_cpo |
| 423 | |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 424 | " vim:sw=4: |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 425 | |