ruby.vim 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. " Vim filetype plugin
  2. " Language: Ruby
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " URL: https://github.com/vim-ruby/vim-ruby
  5. " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
  6. " Last Change: 2022 Mar 21
  7. if (exists("b:did_ftplugin"))
  8. finish
  9. endif
  10. let b:did_ftplugin = 1
  11. let s:cpo_save = &cpo
  12. set cpo&vim
  13. if has("gui_running") && !has("gui_win32")
  14. setlocal keywordprg=ri\ -T\ -f\ bs
  15. else
  16. setlocal keywordprg=ri
  17. endif
  18. " Matchit support
  19. if exists("loaded_matchit") && !exists("b:match_words")
  20. let b:match_ignorecase = 0
  21. let b:match_words =
  22. \ '{\|\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|=\@<!begin\)\>=\@!' .
  23. \ ':' .
  24. \ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' .
  25. \ ':' .
  26. \ '}\|\%(^\|[^.\:@$=]\)\@<=\<end\:\@!\>' .
  27. \ ',^=begin\>:^=end\>,' .
  28. \ ',\[:\],(:)'
  29. let b:match_skip =
  30. \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
  31. \ "\\<ruby\\%(String\\|.\+Delimiter\\|Character\\|.\+Escape\\|" .
  32. \ "Regexp\\|Interpolation\\|Comment\\|Documentation\\|" .
  33. \ "ConditionalModifier\\|RepeatModifier\\|RescueModifier\\|OptionalDo\\|" .
  34. \ "MethodName\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" .
  35. \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'"
  36. endif
  37. setlocal formatoptions-=t formatoptions+=croql
  38. setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\)
  39. setlocal suffixesadd=.rb
  40. if exists("&ofu") && has("ruby")
  41. setlocal omnifunc=rubycomplete#Complete
  42. endif
  43. " TODO:
  44. "setlocal define=^\\s*def
  45. setlocal comments=b:#
  46. setlocal commentstring=#\ %s
  47. if !exists('g:ruby_version_paths')
  48. let g:ruby_version_paths = {}
  49. endif
  50. function! s:query_path(root) abort
  51. let code = "print $:.join %q{,}"
  52. if &shell =~# 'sh' && empty(&shellxquote)
  53. let prefix = 'env PATH='.shellescape($PATH).' '
  54. else
  55. let prefix = ''
  56. endif
  57. if &shellxquote == "'"
  58. let path_check = prefix.'ruby --disable-gems -e "' . code . '"'
  59. else
  60. let path_check = prefix."ruby --disable-gems -e '" . code . "'"
  61. endif
  62. let cd = haslocaldir() ? 'lcd' : 'cd'
  63. let cwd = fnameescape(getcwd())
  64. try
  65. exe cd fnameescape(a:root)
  66. let path = split(system(path_check),',')
  67. exe cd cwd
  68. return path
  69. finally
  70. exe cd cwd
  71. endtry
  72. endfunction
  73. function! s:build_path(path) abort
  74. let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',')
  75. if &g:path =~# '\v^%(\.,)=%(/%(usr|emx)/include,)=,$'
  76. let path = path . ',.,,'
  77. elseif &g:path =~# ',\.,,$'
  78. let path = &g:path[0:-4] . path . ',.,,'
  79. elseif &g:path =~# ',,$'
  80. let path = &g:path[0:-2] . path . ',,'
  81. else
  82. let path = substitute(&g:path, '[^,]\zs$', ',', '') . path
  83. endif
  84. return path
  85. endfunction
  86. if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h'))
  87. let s:version_file = findfile('.ruby-version', '.;')
  88. if !empty(s:version_file) && filereadable(s:version_file)
  89. let b:ruby_version = get(readfile(s:version_file, '', 1), '')
  90. if !has_key(g:ruby_version_paths, b:ruby_version)
  91. let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h'))
  92. endif
  93. endif
  94. endif
  95. if exists("g:ruby_path")
  96. let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path
  97. elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', ''))
  98. let s:ruby_paths = g:ruby_version_paths[b:ruby_version]
  99. let s:ruby_path = s:build_path(s:ruby_paths)
  100. else
  101. if !exists('g:ruby_default_path')
  102. if has("ruby") && has("win32")
  103. ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) )
  104. elseif executable('ruby') && !empty($HOME)
  105. let g:ruby_default_path = s:query_path($HOME)
  106. else
  107. let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val')
  108. endif
  109. endif
  110. let s:ruby_paths = g:ruby_default_path
  111. let s:ruby_path = s:build_path(s:ruby_paths)
  112. endif
  113. if stridx(&l:path, s:ruby_path) == -1
  114. let &l:path = s:ruby_path
  115. endif
  116. if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1
  117. let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',')
  118. endif
  119. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  120. let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
  121. \ "All Files (*.*)\t*.*\n"
  122. endif
  123. let b:undo_ftplugin = "setl inc= sua= path= tags= fo< com< cms< kp="
  124. \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
  125. \."| if exists('&ofu') && has('ruby') | setl ofu< | endif"
  126. if get(g:, 'ruby_recommended_style', 1)
  127. setlocal shiftwidth=2 softtabstop=2 expandtab
  128. let b:undo_ftplugin .= ' | setl sw< sts< et<'
  129. endif
  130. " To activate, :set ballooneval
  131. if exists('+balloonexpr') && get(g:, 'ruby_balloonexpr')
  132. setlocal balloonexpr=RubyBalloonexpr()
  133. let b:undo_ftplugin .= "| setl bexpr="
  134. endif
  135. function! s:map(mode, flags, map) abort
  136. let from = matchstr(a:map, '\S\+')
  137. if empty(mapcheck(from, a:mode))
  138. exe a:mode.'map' '<buffer>' a:flags a:map
  139. let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from
  140. endif
  141. endfunction
  142. cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
  143. cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
  144. let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>"
  145. if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
  146. nmap <buffer><script> <SID>: :<C-U>
  147. nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR>
  148. cmap <buffer> <SID><cfile> <Plug><cfile>
  149. cmap <buffer> <SID><ctag> <Plug><ctag>
  150. nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','n')<CR>
  151. nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','n')<CR>
  152. nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','n')<CR>
  153. nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','n')<CR>
  154. xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','v')<CR>
  155. xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','v')<CR>
  156. xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','v')<CR>
  157. xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','v')<CR>
  158. nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','n')<CR>
  159. nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','n')<CR>
  160. nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','n')<CR>
  161. nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','n')<CR>
  162. xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','v')<CR>
  163. xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','v')<CR>
  164. xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','v')<CR>
  165. xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','v')<CR>
  166. let b:undo_ftplugin = b:undo_ftplugin
  167. \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
  168. \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
  169. if maparg('im','x') == '' && maparg('im','o') == '' && maparg('am','x') == '' && maparg('am','o') == ''
  170. onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
  171. onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
  172. xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
  173. xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
  174. let b:undo_ftplugin = b:undo_ftplugin
  175. \."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'"
  176. \."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'"
  177. endif
  178. if maparg('iM','x') == '' && maparg('iM','o') == '' && maparg('aM','x') == '' && maparg('aM','o') == ''
  179. onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
  180. onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
  181. xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
  182. xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
  183. let b:undo_ftplugin = b:undo_ftplugin
  184. \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'"
  185. \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'"
  186. endif
  187. call s:map('c', '', '<C-R><C-F> <Plug><cfile>')
  188. cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : ''
  189. call s:map('n', '<script><silent>', '<C-]> <SID>:exe v:count1."tag <SID><ctag>"<SID>tagzv<CR>')
  190. call s:map('n', '<script><silent>', 'g<C-]> <SID>:exe "tjump <SID><ctag>"<SID>tagzv<CR>')
  191. call s:map('n', '<script><silent>', 'g] <SID>:exe "tselect <SID><ctag>"<SID>tagzv<CR>')
  192. call s:map('n', '<script><silent>', '<C-W>] <SID>:exe v:count1."stag <SID><ctag>"<SID>tagzv<CR>')
  193. call s:map('n', '<script><silent>', '<C-W><C-]> <SID>:exe v:count1."stag <SID><ctag>"<SID>tagzv<CR>')
  194. call s:map('n', '<script><silent>', '<C-W>g<C-]> <SID>:exe "stjump <SID><ctag>"<SID>tagzv<CR>')
  195. call s:map('n', '<script><silent>', '<C-W>g] <SID>:exe "stselect <SID><ctag>"<SID>tagzv<CR>')
  196. call s:map('n', '<script><silent>', '<C-W>} <SID>:exe v:count1."ptag <SID><ctag>"<CR>')
  197. call s:map('n', '<script><silent>', '<C-W>g} <SID>:exe "ptjump <SID><ctag>"<CR>')
  198. call s:map('n', '<script><silent>', 'gf <SID>c:find <SID><cfile><CR>')
  199. call s:map('n', '<script><silent>', '<C-W>f <SID>c:sfind <SID><cfile><CR>')
  200. call s:map('n', '<script><silent>', '<C-W><C-F> <SID>c:sfind <SID><cfile><CR>')
  201. call s:map('n', '<script><silent>', '<C-W>gf <SID>c:tabfind <SID><cfile><CR>')
  202. endif
  203. let &cpo = s:cpo_save
  204. unlet s:cpo_save
  205. if exists("g:did_ruby_ftplugin_functions")
  206. finish
  207. endif
  208. let g:did_ruby_ftplugin_functions = 1
  209. function! RubyBalloonexpr() abort
  210. if !exists('s:ri_found')
  211. let s:ri_found = executable('ri')
  212. endif
  213. if s:ri_found
  214. let line = getline(v:beval_lnum)
  215. let b = matchstr(strpart(line,0,v:beval_col),'\%(\w\|[:.]\)*$')
  216. let a = substitute(matchstr(strpart(line,v:beval_col),'^\w*\%([?!]\|\s*=\)\?'),'\s\+','','g')
  217. let str = b.a
  218. let before = strpart(line,0,v:beval_col-strlen(b))
  219. let after = strpart(line,v:beval_col+strlen(a))
  220. if str =~ '^\.'
  221. let str = substitute(str,'^\.','#','g')
  222. if before =~ '\]\s*$'
  223. let str = 'Array'.str
  224. elseif before =~ '}\s*$'
  225. " False positives from blocks here
  226. let str = 'Hash'.str
  227. elseif before =~ "[\"'`]\\s*$" || before =~ '\$\d\+\s*$'
  228. let str = 'String'.str
  229. elseif before =~ '\$\d\+\.\d\+\s*$'
  230. let str = 'Float'.str
  231. elseif before =~ '\$\d\+\s*$'
  232. let str = 'Integer'.str
  233. elseif before =~ '/\s*$'
  234. let str = 'Regexp'.str
  235. else
  236. let str = substitute(str,'^#','.','')
  237. endif
  238. endif
  239. let str = substitute(str,'.*\.\s*to_f\s*\.\s*','Float#','')
  240. let str = substitute(str,'.*\.\s*to_i\%(nt\)\=\s*\.\s*','Integer#','')
  241. let str = substitute(str,'.*\.\s*to_s\%(tr\)\=\s*\.\s*','String#','')
  242. let str = substitute(str,'.*\.\s*to_sym\s*\.\s*','Symbol#','')
  243. let str = substitute(str,'.*\.\s*to_a\%(ry\)\=\s*\.\s*','Array#','')
  244. let str = substitute(str,'.*\.\s*to_proc\s*\.\s*','Proc#','')
  245. if str !~ '^\w'
  246. return ''
  247. endif
  248. silent! let res = substitute(system("ri -f rdoc -T \"".str.'"'),'\n$','','')
  249. if res =~ '^Nothing known about' || res =~ '^Bad argument:' || res =~ '^More than one method'
  250. return ''
  251. endif
  252. return res
  253. else
  254. return ""
  255. endif
  256. endfunction
  257. function! s:searchsyn(pattern, syn, flags, mode) abort
  258. let cnt = v:count1
  259. norm! m'
  260. if a:mode ==# 'v'
  261. norm! gv
  262. endif
  263. let i = 0
  264. call map(a:syn, 'hlID(v:val)')
  265. while i < cnt
  266. let i = i + 1
  267. let line = line('.')
  268. let col = col('.')
  269. let pos = search(a:pattern,'W'.a:flags)
  270. while pos != 0 && index(a:syn, s:synid()) < 0
  271. let pos = search(a:pattern,'W'.a:flags)
  272. endwhile
  273. if pos == 0
  274. call cursor(line,col)
  275. return
  276. endif
  277. endwhile
  278. endfunction
  279. function! s:synid() abort
  280. return synID(line('.'),col('.'),0)
  281. endfunction
  282. function! s:wrap_i(back,forward) abort
  283. execute 'norm! k'
  284. execute 'norm '.a:forward
  285. let line = line('.')
  286. execute 'norm '.a:back
  287. if line('.') == line - 1
  288. return s:wrap_a(a:back,a:forward)
  289. endif
  290. execute 'norm! jV'
  291. execute 'norm '.a:forward
  292. execute 'norm! k'
  293. endfunction
  294. function! s:wrap_a(back,forward) abort
  295. execute 'norm '.a:forward
  296. if line('.') < line('$') && getline(line('.')+1) ==# ''
  297. let after = 1
  298. endif
  299. execute 'norm '.a:back
  300. while getline(line('.')-1) =~# '^\s*#' && line('.')
  301. -
  302. endwhile
  303. if exists('after')
  304. execute 'norm! V'
  305. execute 'norm '.a:forward
  306. execute 'norm! j'
  307. elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$'
  308. execute 'norm! kV'
  309. execute 'norm '.a:forward
  310. else
  311. execute 'norm! V'
  312. execute 'norm '.a:forward
  313. endif
  314. endfunction
  315. function! RubyCursorIdentifier() abort
  316. let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)'
  317. let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode
  318. let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)'
  319. let method = '\%(\.[_a-zA-Z]\w*\s*=>\@!\|\<[_a-zA-Z]\w*\>[?!]\=\)'
  320. let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)'
  321. let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)'
  322. let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)'
  323. let [lnum, col] = searchpos(pattern,'bcn',line('.'))
  324. let raw = matchstr(getline('.')[col-1 : ],pattern)
  325. let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','')
  326. return stripped == '' ? expand("<cword>") : stripped
  327. endfunction
  328. function! RubyCursorTag() abort
  329. return substitute(RubyCursorIdentifier(), '^[$@]*', '', '')
  330. endfunction
  331. function! RubyCursorFile() abort
  332. let isfname = &isfname
  333. try
  334. set isfname+=:
  335. let cfile = expand('<cfile>')
  336. finally
  337. let isfname = &isfname
  338. endtry
  339. let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!')
  340. let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*')
  341. if s:synid() ==# hlID('rubyConstant')
  342. let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','')
  343. let cfile = substitute(cfile,'^::','','')
  344. let cfile = substitute(cfile,'::','/','g')
  345. let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g')
  346. let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g')
  347. return tolower(cfile) . '.rb'
  348. elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$'
  349. let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
  350. let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
  351. elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$'
  352. let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1')
  353. let cfile = expand('%:p:h') . target
  354. let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
  355. elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$'
  356. let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
  357. let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
  358. elseif pre.post =~# '\<File.expand_path[( ].*[''"]\{2\}, *__FILE__\>' && cfile =~# '^\.\.'
  359. let cfile = expand('%:p:h') . strpart(cfile, 2)
  360. else
  361. return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '')
  362. endif
  363. let cwdpat = '^\M' . substitute(getcwd(), '[\/]', '\\[\\/]', 'g').'\ze\[\/]'
  364. let cfile = substitute(cfile, cwdpat, '.', '')
  365. if fnameescape(cfile) !=# cfile
  366. return '+ '.fnameescape(cfile)
  367. else
  368. return cfile
  369. endif
  370. endfunction
  371. "
  372. " Instructions for enabling "matchit" support:
  373. "
  374. " 1. Look for the latest "matchit" plugin at
  375. "
  376. " http://www.vim.org/scripts/script.php?script_id=39
  377. "
  378. " It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
  379. "
  380. " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
  381. "
  382. " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
  383. "
  384. " 4. Ensure this file (ftplugin/ruby.vim) is installed.
  385. "
  386. " 5. Ensure you have this line in your $HOME/.vimrc:
  387. " filetype plugin on
  388. "
  389. " 6. Restart Vim and create the matchit documentation:
  390. "
  391. " :helptags ~/.vim/doc
  392. "
  393. " Now you can do ":help matchit", and you should be able to use "%" on Ruby
  394. " keywords. Try ":echo b:match_words" to be sure.
  395. "
  396. " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
  397. " locations of plugin directories, etc., as there are several options, and it
  398. " differs on Windows. Email gsinclair@soyabean.com.au if you need help.
  399. "
  400. " vim: nowrap sw=2 sts=2 ts=8: