blob: 9630a940ab3f821d42ecee5a65d3af7d41e2836e [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002" Language: Ruby
Bram Moolenaarec7944a2013-06-12 21:29:15 +02003" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4" URL: https://github.com/vim-ruby/vim-ruby
Bram Moolenaar756ec0f2007-05-05 17:59:48 +00005" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaar60a795a2005-09-16 21:55:43 +00006" ----------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
Bram Moolenaar071d4272004-06-13 20:20:40 +00008if (exists("b:did_ftplugin"))
Bram Moolenaar60a795a2005-09-16 21:55:43 +00009 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000010endif
11let b:did_ftplugin = 1
12
Bram Moolenaar60a795a2005-09-16 21:55:43 +000013let s:cpo_save = &cpo
14set cpo&vim
15
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000016if has("gui_running") && !has("gui_win32")
Bram Moolenaarec7944a2013-06-12 21:29:15 +020017 setlocal keywordprg=ri\ -T\ -f\ bs
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000018else
19 setlocal keywordprg=ri
20endif
21
Bram Moolenaar60a795a2005-09-16 21:55:43 +000022" Matchit support
23if exists("loaded_matchit") && !exists("b:match_words")
24 let b:match_ignorecase = 0
25
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000026 let b:match_words =
Bram Moolenaar79166c42007-05-10 18:29:51 +000027 \ '\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|begin\)\>=\@!' .
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000028 \ ':' .
Bram Moolenaar79166c42007-05-10 18:29:51 +000029 \ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' .
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000030 \ ':' .
Bram Moolenaar79166c42007-05-10 18:29:51 +000031 \ '\<end\>' .
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000032 \ ',{:},\[:\],(:)'
Bram Moolenaar60a795a2005-09-16 21:55:43 +000033
34 let b:match_skip =
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000035 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
Bram Moolenaar79166c42007-05-10 18:29:51 +000036 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Escape\\|" .
37 \ "Interpolation\\|NoInterpolation\\|Comment\\|Documentation\\|" .
38 \ "ConditionalModifier\\|RepeatModifier\\|OptionalDo\\|" .
39 \ "Function\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" .
40 \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'"
Bram Moolenaar60a795a2005-09-16 21:55:43 +000041endif
42
43setlocal formatoptions-=t formatoptions+=croql
44
Bram Moolenaarec7944a2013-06-12 21:29:15 +020045setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\)
Bram Moolenaar60a795a2005-09-16 21:55:43 +000046setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
47setlocal suffixesadd=.rb
Bram Moolenaarc6249bb2006-04-15 20:25:09 +000048
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000049if exists("&ofu") && has("ruby")
Bram Moolenaarc6249bb2006-04-15 20:25:09 +000050 setlocal omnifunc=rubycomplete#Complete
51endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +000052
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000053" To activate, :set ballooneval
54if has('balloon_eval') && exists('+balloonexpr')
55 setlocal balloonexpr=RubyBalloonexpr()
56endif
57
58
Bram Moolenaar60a795a2005-09-16 21:55:43 +000059" TODO:
60"setlocal define=^\\s*def
61
62setlocal comments=:#
63setlocal commentstring=#\ %s
64
Bram Moolenaarec7944a2013-06-12 21:29:15 +020065if !exists('g:ruby_version_paths')
66 let g:ruby_version_paths = {}
67endif
68
69function! s:query_path(root)
70 let code = "print $:.join %q{,}"
71 if &shell =~# 'sh' && $PATH !~# '\s'
72 let prefix = 'env PATH='.$PATH.' '
Bram Moolenaar60a795a2005-09-16 21:55:43 +000073 else
Bram Moolenaarec7944a2013-06-12 21:29:15 +020074 let prefix = ''
75 endif
76 if &shellxquote == "'"
77 let path_check = prefix.'ruby -e "' . code . '"'
78 else
79 let path_check = prefix."ruby -e '" . code . "'"
80 endif
81
82 let cd = haslocaldir() ? 'lcd' : 'cd'
83 let cwd = getcwd()
84 try
85 exe cd fnameescape(a:root)
86 let path = split(system(path_check),',')
87 exe cd fnameescape(cwd)
88 return path
89 finally
90 exe cd fnameescape(cwd)
91 endtry
92endfunction
93
94function! s:build_path(path)
95 let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',')
96 if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$'
97 let path = substitute(&g:path,',,$',',','') . ',' . path
98 endif
99 return path
100endfunction
101
102if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h'))
103 let s:version_file = findfile('.ruby-version', '.;')
104 if !empty(s:version_file)
105 let b:ruby_version = get(readfile(s:version_file, '', 1), '')
106 if !has_key(g:ruby_version_paths, b:ruby_version)
107 let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h'))
108 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000109 endif
110endif
111
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200112if exists("g:ruby_path")
113 let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path
114elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', ''))
115 let s:ruby_paths = g:ruby_version_paths[b:ruby_version]
116 let s:ruby_path = s:build_path(s:ruby_paths)
117else
118 if !exists('g:ruby_default_path')
119 if has("ruby") && has("win32")
120 ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) )
121 elseif executable('ruby')
122 let g:ruby_default_path = s:query_path($HOME)
123 else
124 let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val')
125 endif
126 endif
127 let s:ruby_paths = g:ruby_default_path
128 let s:ruby_path = s:build_path(s:ruby_paths)
129endif
130
131if stridx(&l:path, s:ruby_path) == -1
132 let &l:path = s:ruby_path
133endif
134if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1
135 let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',')
136endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000137
138if has("gui_win32") && !exists("b:browsefilter")
139 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000140 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000141endif
142
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200143let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< tags< kp<"
Bram Moolenaar79166c42007-05-10 18:29:51 +0000144 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
145 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif"
146 \."| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
147
148if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
Bram Moolenaar1d689522010-05-28 20:54:39 +0200149 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','n')<CR>
150 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','n')<CR>
151 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','n')<CR>
152 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','n')<CR>
153 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','v')<CR>
154 xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','v')<CR>
155 xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','v')<CR>
156 xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','v')<CR>
Bram Moolenaar79166c42007-05-10 18:29:51 +0000157
Bram Moolenaar1d689522010-05-28 20:54:39 +0200158 nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b','n')<CR>
159 nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','','n')<CR>
160 nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b','n')<CR>
161 nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','','n')<CR>
162 xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b','v')<CR>
163 xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','','v')<CR>
164 xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b','v')<CR>
165 xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','','v')<CR>
Bram Moolenaar79166c42007-05-10 18:29:51 +0000166
167 let b:undo_ftplugin = b:undo_ftplugin
168 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
169 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
Bram Moolenaar1d689522010-05-28 20:54:39 +0200170
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200171 if maparg('im','n') == ''
172 onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
173 onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
174 xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
175 xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
176 let b:undo_ftplugin = b:undo_ftplugin
177 \."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'"
178 \."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'"
179 endif
180
181 if maparg('iM','n') == ''
182 onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
183 onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
184 xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
185 xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
186 let b:undo_ftplugin = b:undo_ftplugin
187 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'"
188 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'"
189 endif
190
Bram Moolenaar1d689522010-05-28 20:54:39 +0200191 if maparg("\<C-]>",'n') == ''
192 nnoremap <silent> <buffer> <C-]> :<C-U>exe v:count1."tag <C-R>=RubyCursorIdentifier()<CR>"<CR>
193 nnoremap <silent> <buffer> g<C-]> :<C-U>exe "tjump <C-R>=RubyCursorIdentifier()<CR>"<CR>
194 nnoremap <silent> <buffer> g] :<C-U>exe "tselect <C-R>=RubyCursorIdentifier()<CR>"<CR>
195 nnoremap <silent> <buffer> <C-W>] :<C-U>exe v:count1."stag <C-R>=RubyCursorIdentifier()<CR>"<CR>
196 nnoremap <silent> <buffer> <C-W><C-]> :<C-U>exe v:count1."stag <C-R>=RubyCursorIdentifier()<CR>"<CR>
197 nnoremap <silent> <buffer> <C-W>g<C-]> :<C-U>exe "stjump <C-R>=RubyCursorIdentifier()<CR>"<CR>
198 nnoremap <silent> <buffer> <C-W>g] :<C-U>exe "stselect <C-R>=RubyCursorIdentifier()<CR>"<CR>
199 nnoremap <silent> <buffer> <C-W>} :<C-U>exe "ptag <C-R>=RubyCursorIdentifier()<CR>"<CR>
200 nnoremap <silent> <buffer> <C-W>g} :<C-U>exe "ptjump <C-R>=RubyCursorIdentifier()<CR>"<CR>
201 let b:undo_ftplugin = b:undo_ftplugin
202 \."| sil! exe 'nunmap <buffer> <C-]>'| sil! exe 'nunmap <buffer> g<C-]>'| sil! exe 'nunmap <buffer> g]'"
203 \."| sil! exe 'nunmap <buffer> <C-W>]'| sil! exe 'nunmap <buffer> <C-W><C-]>'"
204 \."| sil! exe 'nunmap <buffer> <C-W>g<C-]>'| sil! exe 'nunmap <buffer> <C-W>g]'"
205 \."| sil! exe 'nunmap <buffer> <C-W>}'| sil! exe 'nunmap <buffer> <C-W>g}'"
206 endif
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200207
208 if maparg("gf",'n') == ''
209 " By using findfile() rather than gf's normal behavior, we prevent
210 " erroneously editing a directory.
211 nnoremap <silent> <buffer> gf :<C-U>exe <SID>gf(v:count1,"gf",'edit')<CR>
212 nnoremap <silent> <buffer> <C-W>f :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>f",'split')<CR>
213 nnoremap <silent> <buffer> <C-W><C-F> :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>\<Lt>C-F>",'split')<CR>
214 nnoremap <silent> <buffer> <C-W>gf :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>gf",'tabedit')<CR>
215 let b:undo_ftplugin = b:undo_ftplugin
216 \."| sil! exe 'nunmap <buffer> gf' | sil! exe 'nunmap <buffer> <C-W>f' | sil! exe 'nunmap <buffer> <C-W><C-F>' | sil! exe 'nunmap <buffer> <C-W>gf'"
217 endif
Bram Moolenaar79166c42007-05-10 18:29:51 +0000218endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000219
220let &cpo = s:cpo_save
221unlet s:cpo_save
222
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000223if exists("g:did_ruby_ftplugin_functions")
224 finish
225endif
226let g:did_ruby_ftplugin_functions = 1
227
228function! RubyBalloonexpr()
229 if !exists('s:ri_found')
230 let s:ri_found = executable('ri')
231 endif
232 if s:ri_found
233 let line = getline(v:beval_lnum)
234 let b = matchstr(strpart(line,0,v:beval_col),'\%(\w\|[:.]\)*$')
235 let a = substitute(matchstr(strpart(line,v:beval_col),'^\w*\%([?!]\|\s*=\)\?'),'\s\+','','g')
236 let str = b.a
237 let before = strpart(line,0,v:beval_col-strlen(b))
238 let after = strpart(line,v:beval_col+strlen(a))
239 if str =~ '^\.'
240 let str = substitute(str,'^\.','#','g')
241 if before =~ '\]\s*$'
242 let str = 'Array'.str
243 elseif before =~ '}\s*$'
244 " False positives from blocks here
245 let str = 'Hash'.str
246 elseif before =~ "[\"'`]\\s*$" || before =~ '\$\d\+\s*$'
247 let str = 'String'.str
248 elseif before =~ '\$\d\+\.\d\+\s*$'
249 let str = 'Float'.str
250 elseif before =~ '\$\d\+\s*$'
251 let str = 'Integer'.str
252 elseif before =~ '/\s*$'
253 let str = 'Regexp'.str
254 else
255 let str = substitute(str,'^#','.','')
256 endif
257 endif
258 let str = substitute(str,'.*\.\s*to_f\s*\.\s*','Float#','')
259 let str = substitute(str,'.*\.\s*to_i\%(nt\)\=\s*\.\s*','Integer#','')
260 let str = substitute(str,'.*\.\s*to_s\%(tr\)\=\s*\.\s*','String#','')
261 let str = substitute(str,'.*\.\s*to_sym\s*\.\s*','Symbol#','')
262 let str = substitute(str,'.*\.\s*to_a\%(ry\)\=\s*\.\s*','Array#','')
263 let str = substitute(str,'.*\.\s*to_proc\s*\.\s*','Proc#','')
264 if str !~ '^\w'
265 return ''
266 endif
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200267 silent! let res = substitute(system("ri -f rdoc -T \"".str.'"'),'\n$','','')
Bram Moolenaar79166c42007-05-10 18:29:51 +0000268 if res =~ '^Nothing known about' || res =~ '^Bad argument:' || res =~ '^More than one method'
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000269 return ''
270 endif
271 return res
272 else
273 return ""
274 endif
275endfunction
276
Bram Moolenaar1d689522010-05-28 20:54:39 +0200277function! s:searchsyn(pattern,syn,flags,mode)
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200278 norm! m'
279 if a:mode ==# 'v'
280 norm! gv
281 endif
282 let i = 0
283 let cnt = v:count ? v:count : 1
284 while i < cnt
285 let i = i + 1
286 let line = line('.')
287 let col = col('.')
288 let pos = search(a:pattern,'W'.a:flags)
289 while pos != 0 && s:synname() !~# a:syn
290 let pos = search(a:pattern,'W'.a:flags)
Bram Moolenaar79166c42007-05-10 18:29:51 +0000291 endwhile
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200292 if pos == 0
293 call cursor(line,col)
294 return
295 endif
296 endwhile
Bram Moolenaar79166c42007-05-10 18:29:51 +0000297endfunction
298
299function! s:synname()
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200300 return synIDattr(synID(line('.'),col('.'),0),'name')
301endfunction
302
303function! s:wrap_i(back,forward)
304 execute 'norm k'.a:forward
305 let line = line('.')
306 execute 'norm '.a:back
307 if line('.') == line - 1
308 return s:wrap_a(a:back,a:forward)
309 endif
310 execute 'norm jV'.a:forward.'k'
311endfunction
312
313function! s:wrap_a(back,forward)
314 execute 'norm '.a:forward
315 if line('.') < line('$') && getline(line('.')+1) ==# ''
316 let after = 1
317 endif
318 execute 'norm '.a:back
319 while getline(line('.')-1) =~# '^\s*#' && line('.')
320 -
321 endwhile
322 if exists('after')
323 execute 'norm V'.a:forward.'j'
324 elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$'
325 execute 'norm kV'.a:forward
326 else
327 execute 'norm V'.a:forward
328 endif
Bram Moolenaar79166c42007-05-10 18:29:51 +0000329endfunction
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000330
Bram Moolenaar1d689522010-05-28 20:54:39 +0200331function! RubyCursorIdentifier()
332 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)'
333 let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode
334 let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)'
335 let method = '\%(\<[_a-zA-Z]\w*\>\%([?!]\|\s*=>\@!\)\=\)'
336 let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)'
337 let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)'
338 let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)'
339 let [lnum, col] = searchpos(pattern,'bcn',line('.'))
340 let raw = matchstr(getline('.')[col-1 : ],pattern)
341 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*:\=','','')
342 return stripped == '' ? expand("<cword>") : stripped
343endfunction
344
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200345function! s:gf(count,map,edit) abort
346 if getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$'
347 let target = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
348 return a:edit.' %:h/'.target.'.rb'
349 elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$'
350 let target = matchstr(getline('.'),'\(["'']\)\.\./\zs.\{-\}\ze\1')
351 return a:edit.' %:h/'.target.'.rb'
352 elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$'
353 let target = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
354 else
355 let target = expand('<cfile>')
356 endif
357 let found = findfile(target, &path, a:count)
358 if found ==# ''
359 return 'norm! '.a:count.a:map
360 else
361 return a:edit.' '.fnameescape(found)
362 endif
363endfunction
364
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000365"
366" Instructions for enabling "matchit" support:
367"
368" 1. Look for the latest "matchit" plugin at
369"
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000370" http://www.vim.org/scripts/script.php?script_id=39
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000371"
372" It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
373"
374" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
375"
376" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
377"
378" 4. Ensure this file (ftplugin/ruby.vim) is installed.
379"
380" 5. Ensure you have this line in your $HOME/.vimrc:
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000381" filetype plugin on
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000382"
383" 6. Restart Vim and create the matchit documentation:
384"
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000385" :helptags ~/.vim/doc
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000386"
387" Now you can do ":help matchit", and you should be able to use "%" on Ruby
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000388" keywords. Try ":echo b:match_words" to be sure.
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000389"
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000390" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000391" locations of plugin directories, etc., as there are several options, and it
392" differs on Windows. Email gsinclair@soyabean.com.au if you need help.
393"
394
Bram Moolenaar446cb832008-06-24 21:56:24 +0000395" vim: nowrap sw=2 sts=2 ts=8: