comparison runtime/ftplugin/sql.vim @ 167:c93c9cad9618

updated for version 7.0051
author vimboss
date Tue, 22 Feb 2005 08:39:57 +0000
parents 3fc0f57ecb91
children 7b21554be7a1
comparison
equal deleted inserted replaced
166:3a28ed993bbe 167:c93c9cad9618
1 " Vim filetype plugin file 1 " SQL filetype plugin file
2 " Language: SQL (Common for Oracle, Microsoft SQL Server, Sybase) 2 " Language: SQL (Common for Oracle, Microsoft SQL Server, Sybase)
3 " Version: 0.02 3 " Version: 0.08
4 " Maintainer: David Fishburn <fishburn@ianywhere.com> 4 " Maintainer: David Fishburn <fishburn at ianywhere dot com>
5 " Last Change: Tue May 27 2003 09:33:31 5 " Last Change: Mon Feb 21 2005 7:27:36 AM
6 " Download: http://vim.sourceforge.net/script.php?script_id=454
6 7
7 " This file should only contain values that are common to all SQL languages 8 " This file should only contain values that are common to all SQL languages
8 " Oracle, Microsoft SQL Server, Sybase ASA/ASE, MySQL, and so on 9 " Oracle, Microsoft SQL Server, Sybase ASA/ASE, MySQL, and so on
9 " If additional features are required create: 10 " If additional features are required create:
10 " vimfiles/after/ftplugin/sql.vim 11 " vimfiles/after/ftplugin/sql.vim (Windows)
11 " to override and add any of your own settings 12 " .vim/after/ftplugin/sql.vim (Unix)
13 " to override and add any of your own settings.
12 14
13 " Only do this when not done yet for this buffer 15 " Only do this when not done yet for this buffer
14 if exists("b:did_ftplugin") 16 if exists("b:did_ftplugin")
15 finish 17 finish
16 endif 18 endif
17 19
20 let s:save_cpo = &cpo
21 set cpo=
22
18 " Don't load another plugin for this buffer 23 " Don't load another plugin for this buffer
19 let b:did_ftplugin = 1 24 let b:did_ftplugin = 1
25
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\+\)\?'
20 30
21 " Define patterns for the matchit macro 31 " Define patterns for the matchit macro
22 if !exists("b:match_words") 32 if !exists("b:match_words")
23 " SQL is generally case insensitive 33 " SQL is generally case insensitive
24 let b:match_ignorecase = 1 34 let b:match_ignorecase = 1
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
25 let b:match_words = 76 let b:match_words =
26 \ '\<begin\>:\<end\>\(;\)\?$,'. 77 \ '\<begin\>:\<end\>\W*$,'.
27 \ '\<if\>:\<elsif\>:\<elseif\>:\<else\>:'. 78 \
28 \ '\%(\<end\s\+\)\@<!' . '\<if\>:\<end\s\+if\>,'. 79 \ s:notend . '\<if\>:'.
29 \ '\<loop\>:\<break\>:\<continue\>:'. 80 \ '\<elsif\>\|\<elseif\>\|\<else\>:'.
30 \ '\%(\<end\s\+\)\@<!' . '\<loop\>:\<end\s\+loop\>,'. 81 \ '\<end\s\+if\>,'.
31 \ '\<for\>:\<break\>:\<continue\>:'. 82 \
32 \ '\%(\<end\s\+\)\@<!' . '\<for\>:\<end\s\+for\>,'. 83 \ '\<do\>\|'.
33 \ '\<case\>:\<when\>:\<default\>:'. 84 \ '\<while\>\|'.
34 \ '\%(\<end\s\+\)\@<!' . '\<case\>:\<end\s\+case\>' 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\>\),' .
35 endif 109 endif
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