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) |
| 3 | " Version: 0.08 |
| 4 | " Maintainer: David Fishburn <fishburn at ianywhere dot com> |
| 5 | " Last Change: Mon Feb 21 2005 7:27:36 AM |
| 6 | " Download: http://vim.sourceforge.net/script.php?script_id=454 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | |
| 8 | " This file should only contain values that are common to all SQL languages |
| 9 | " Oracle, Microsoft SQL Server, Sybase ASA/ASE, MySQL, and so on |
| 10 | " If additional features are required create: |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 11 | " vimfiles/after/ftplugin/sql.vim (Windows) |
| 12 | " .vim/after/ftplugin/sql.vim (Unix) |
| 13 | " to override and add any of your own settings. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | |
| 15 | " Only do this when not done yet for this buffer |
| 16 | if exists("b:did_ftplugin") |
| 17 | finish |
| 18 | endif |
| 19 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 20 | let s:save_cpo = &cpo |
| 21 | set cpo= |
| 22 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | " Don't load another plugin for this buffer |
| 24 | let b:did_ftplugin = 1 |
| 25 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 26 | " Some standard expressions for use with the matchit strings |
| 27 | let s:notend = '\%(\<end\s\+\)\@<!' |
| 28 | let s:when_no_matched_or_others = '\%(\<when\>\%(\s\+\%(\%(\<not\>\s\+\)\?<matched\>\)\|\<others\>\)\@!\)' |
| 29 | let s:or_replace = '\%(or\s\+replace\s\+\)\?' |
| 30 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 31 | " Define patterns for the matchit macro |
| 32 | if !exists("b:match_words") |
| 33 | " SQL is generally case insensitive |
| 34 | let b:match_ignorecase = 1 |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 35 | |
| 36 | " Handle the following: |
| 37 | " if |
| 38 | " elseif | elsif |
| 39 | " else [if] |
| 40 | " end if |
| 41 | " |
| 42 | " [while condition] loop |
| 43 | " leave |
| 44 | " break |
| 45 | " continue |
| 46 | " exit |
| 47 | " end loop |
| 48 | " |
| 49 | " for |
| 50 | " leave |
| 51 | " break |
| 52 | " continue |
| 53 | " exit |
| 54 | " end loop |
| 55 | " |
| 56 | " do |
| 57 | " statements |
| 58 | " doend |
| 59 | " |
| 60 | " case |
| 61 | " when |
| 62 | " when |
| 63 | " default |
| 64 | " end case |
| 65 | " |
| 66 | " merge |
| 67 | " when not matched |
| 68 | " when matched |
| 69 | " |
| 70 | " EXCEPTION |
| 71 | " WHEN column_not_found THEN |
| 72 | " WHEN OTHERS THEN |
| 73 | " |
| 74 | " create[ or replace] procedure|function|event |
| 75 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | let b:match_words = |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 77 | \ '\<begin\>:\<end\>\W*$,'. |
| 78 | \ |
| 79 | \ s:notend . '\<if\>:'. |
| 80 | \ '\<elsif\>\|\<elseif\>\|\<else\>:'. |
| 81 | \ '\<end\s\+if\>,'. |
| 82 | \ |
| 83 | \ '\<do\>\|'. |
| 84 | \ '\<while\>\|'. |
| 85 | \ '\%(' . s:notend . '\<loop\>\)\|'. |
| 86 | \ '\%(' . s:notend . '\<for\>\):'. |
| 87 | \ '\<exit\>\|\<leave\>\|\<break\>\|\<continue\>:'. |
| 88 | \ '\%(\<end\s\+\%(for\|loop\>\)\)\|\<doend\>,'. |
| 89 | \ |
| 90 | \ '\%('. s:notend . '\<case\>\):'. |
| 91 | \ '\%('.s:when_no_matched_or_others.'\):'. |
| 92 | \ '\%(\<when\s\+others\>\|\<end\s\+case\>\),' . |
| 93 | \ |
| 94 | \ '\<merge\>:' . |
| 95 | \ '\<when\s\+not\s\+matched\>:' . |
| 96 | \ '\<when\s\+matched\>,' . |
| 97 | \ |
| 98 | \ '\%(\<create\s\+' . s:or_replace . '\)\?'. |
| 99 | \ '\%(function\|procedure\|event\):'. |
| 100 | \ '\<returns\?\>' |
| 101 | " \ '\<begin\>\|\<returns\?\>:'. |
| 102 | " \ '\<end\>\(;\)\?\s*$' |
| 103 | " \ '\<exception\>:'.s:when_no_matched_or_others. |
| 104 | " \ ':\<when\s\+others\>,'. |
| 105 | " |
| 106 | " \ '\%(\<exception\>\|\%('. s:notend . '\<case\>\)\):'. |
| 107 | " \ '\%(\<default\>\|'.s:when_no_matched_or_others.'\):'. |
| 108 | " \ '\%(\%(\<when\s\+others\>\)\|\<end\s\+case\>\),' . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 109 | endif |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 110 | |
| 111 | " Define how to find the macro definition of a variable using the various |
| 112 | " [d, [D, [_CTRL_D and so on features |
| 113 | " Match these values ignoring case |
| 114 | " ie DECLARE varname INTEGER |
| 115 | let &l:define = '\c\(DECLARE\|IN\|OUT\|INOUT\)\s*' |
| 116 | |
| 117 | |
| 118 | " Mappings to move to the next BEGIN ... END block |
| 119 | " \W - no characters or digits |
| 120 | nmap <buffer> <silent> ]] :call search('\c^\s*begin\>', 'W' )<CR> |
| 121 | nmap <buffer> <silent> [[ :call search('\c^\s*begin\>', 'bW' )<CR> |
| 122 | nmap <buffer> <silent> ][ :call search('\c^\s*end\W*$', 'W' )<CR> |
| 123 | nmap <buffer> <silent> [] :call search('\c^\s*end\W*$', 'bW' )<CR> |
| 124 | vmap <buffer> <silent> ]] /\c^\s*begin\><CR> |
| 125 | vmap <buffer> <silent> [[ ?\c^\s*begin<CR> |
| 126 | vmap <buffer> <silent> ][ /\c^\s*end\W*$<CR> |
| 127 | vmap <buffer> <silent> [] ?\c^\s*end\W*$<CR> |
| 128 | |
| 129 | |
| 130 | " Predefined SQL objects what are used by the below mappings using |
| 131 | " the ]} style maps. |
| 132 | " This global variable allows the users to override it's value |
| 133 | " from within their vimrc. |
| 134 | if !exists('g:ftplugin_sql_objects') |
| 135 | let g:ftplugin_sql_objects = 'function,procedure,event,' . |
| 136 | \ '\(existing\\|global\s\+temporary\s\+\)\?table,trigger' . |
| 137 | \ ',schema,service,publication,database,datatype,domain' . |
| 138 | \ ',index,subscription,synchronization,view,variable' |
| 139 | endif |
| 140 | |
| 141 | let s:ftplugin_sql_objects = |
| 142 | \ '\c^\s*' . |
| 143 | \ '\(create\s\+\(or\s\+replace\s\+\)\?\)\?' . |
| 144 | \ '\<\(' . |
| 145 | \ substitute(g:ftplugin_sql_objects, ',', '\\\\|', 'g') . |
| 146 | \ '\)\>' |
| 147 | |
| 148 | " Mappings to move to the next CREATE ... block |
| 149 | " map <buffer> <silent> ]} :call search(g:ftplugin_sql_objects, 'W' )<CR> |
| 150 | " nmap <buffer> <silent> [{ :call search('\c^\s*\(create\s\+\(or\s\+replace\s\+\)\?\)\?\<\(function\\|procedure\\|event\\|table\\|trigger\\|schema\)\>', 'bW' )<CR> |
| 151 | " exec 'nmap <buffer> <silent> ]} /'.s:ftplugin_sql_objects.'<CR>' |
| 152 | exec "nmap <buffer> <silent> ]} :call search('".s:ftplugin_sql_objects."', 'W')<CR>" |
| 153 | exec "nmap <buffer> <silent> [{ :call search('".s:ftplugin_sql_objects."', 'bW')<CR>" |
| 154 | " Could not figure out how to use a :call search() string in visual mode |
| 155 | " without it ending visual mode |
| 156 | exec 'vmap <buffer> <silent> ]} /'.s:ftplugin_sql_objects.'<CR>' |
| 157 | exec 'vmap <buffer> <silent> [{ ?'.s:ftplugin_sql_objects.'<CR>' |
| 158 | " vmap <buffer> <silent> ]} /\c^\s*\(create\s\+\(or\s\+replace\s\+\)\?\)\?\<\(function\\|procedure\\|event\\|table\\|trigger\\|schema\)\><CR> |
| 159 | " vmap <buffer> <silent> [{ ?\c^\s*\(create\s\+\(or\s\+replace\s\+\)\?\)\?\<\(function\\|procedure\\|event\\|table\\|trigger\\|schema\)\><CR> |
| 160 | |
| 161 | " Mappings to move to the next COMMENT |
| 162 | " |
| 163 | " Had to double the \ for the \| separator since this has a special |
| 164 | " meaning on maps |
| 165 | let b:comment_leader = '\(--\\|\/\/\\|\*\\|\/\*\\|\*\/\)' |
| 166 | " Find the start of the next comment |
| 167 | let b:comment_start = '^\(\s*'.b:comment_leader.'.*\n\)\@<!'. |
| 168 | \ '\(\s*'.b:comment_leader.'\)' |
| 169 | " Find the end of the previous comment |
| 170 | let b:comment_end = '\(^\s*'.b:comment_leader.'.*\n\)'. |
| 171 | \ '\(^\s*'.b:comment_leader.'\)\@!' |
| 172 | " Skip over the comment |
| 173 | let b:comment_jump_over = "call search('". |
| 174 | \ '^\(\s*'.b:comment_leader.'.*\n\)\@<!'. |
| 175 | \ "', 'W')" |
| 176 | let b:comment_skip_back = "call search('". |
| 177 | \ '^\(\s*'.b:comment_leader.'.*\n\)\@<!'. |
| 178 | \ "', 'bW')" |
| 179 | " Move to the start and end of comments |
| 180 | exec 'nnoremap <silent><buffer> ]" /'.b:comment_start.'<CR>' |
| 181 | exec 'nnoremap <silent><buffer> [" /'.b:comment_end.'<CR>' |
| 182 | exec 'vnoremap <silent><buffer> ]" /'.b:comment_start.'<CR>' |
| 183 | exec 'vnoremap <silent><buffer> [" /'.b:comment_end.'<CR>' |
| 184 | |
| 185 | " Comments can be of the form: |
| 186 | " /* |
| 187 | " * |
| 188 | " */ |
| 189 | " or |
| 190 | " // |
| 191 | " or |
| 192 | " -- |
| 193 | setlocal comments=s1:/*,mb:*,ex:*/,:--,:// |
| 194 | |
| 195 | let &cpo = s:save_cpo |
| 196 | |
| 197 | " vim:sw=4:ff=unix: |
| 198 | |