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