" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns
" ----------------------------------------------------------------------------
if (exists("b:did_ftplugin"))
finish
endif
let b:did_ftplugin = 1
let s:cpo_save = &cpo
set cpo&vim
if has("gui_running") && !has("gui_win32")
setlocal keywordprg=ri\ -T\ -f\ bs
else
setlocal keywordprg=ri
endif
" Matchit support
if exists("loaded_matchit") && !exists("b:match_words")
let b:match_ignorecase = 0
let b:match_words =
\ '\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|begin\)\>=\@!' .
\ ':' .
\ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' .
\ ':' .
\ '\' .
\ ',{:},\[:\],(:)'
let b:match_skip =
\ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
\ "\\'"
endif
setlocal formatoptions-=t formatoptions+=croql
setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\)
setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
setlocal suffixesadd=.rb
if exists("&ofu") && has("ruby")
setlocal omnifunc=rubycomplete#Complete
endif
" To activate, :set ballooneval
if has('balloon_eval') && exists('+balloonexpr')
setlocal balloonexpr=RubyBalloonexpr()
endif
" TODO:
"setlocal define=^\\s*def
setlocal comments=:#
setlocal commentstring=#\ %s
if !exists('g:ruby_version_paths')
let g:ruby_version_paths = {}
endif
function! s:query_path(root)
let code = "print $:.join %q{,}"
if &shell =~# 'sh' && $PATH !~# '\s'
let prefix = 'env PATH='.$PATH.' '
else
let prefix = ''
endif
if &shellxquote == "'"
let path_check = prefix.'ruby -e "' . code . '"'
else
let path_check = prefix."ruby -e '" . code . "'"
endif
let cd = haslocaldir() ? 'lcd' : 'cd'
let cwd = getcwd()
try
exe cd fnameescape(a:root)
let path = split(system(path_check),',')
exe cd fnameescape(cwd)
return path
finally
exe cd fnameescape(cwd)
endtry
endfunction
function! s:build_path(path)
let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',')
if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$'
let path = substitute(&g:path,',,$',',','') . ',' . path
endif
return path
endfunction
if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h'))
let s:version_file = findfile('.ruby-version', '.;')
if !empty(s:version_file)
let b:ruby_version = get(readfile(s:version_file, '', 1), '')
if !has_key(g:ruby_version_paths, b:ruby_version)
let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h'))
endif
endif
endif
if exists("g:ruby_path")
let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path
elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', ''))
let s:ruby_paths = g:ruby_version_paths[b:ruby_version]
let s:ruby_path = s:build_path(s:ruby_paths)
else
if !exists('g:ruby_default_path')
if has("ruby") && has("win32")
ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) )
elseif executable('ruby')
let g:ruby_default_path = s:query_path($HOME)
else
let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val')
endif
endif
let s:ruby_paths = g:ruby_default_path
let s:ruby_path = s:build_path(s:ruby_paths)
endif
if stridx(&l:path, s:ruby_path) == -1
let &l:path = s:ruby_path
endif
if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1
let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',')
endif
if has("gui_win32") && !exists("b:browsefilter")
let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
\ "All Files (*.*)\t*.*\n"
endif
let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< tags< kp<"
\."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
\."| if exists('&ofu') && has('ruby') | setl ofu< | endif"
\."| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
nnoremap [m :call searchsyn('\','rubyDefine','b','n')
nnoremap ]m :call searchsyn('\','rubyDefine','','n')
nnoremap [M :call searchsyn('\','rubyDefine','b','n')
nnoremap ]M :call searchsyn('\','rubyDefine','','n')
xnoremap [m :call searchsyn('\','rubyDefine','b','v')
xnoremap ]m :call searchsyn('\','rubyDefine','','v')
xnoremap [M :call searchsyn('\','rubyDefine','b','v')
xnoremap ]M :call searchsyn('\','rubyDefine','','v')
nnoremap [[ :call searchsyn('\<\%(class\module\)\>','rubyModule\rubyClass','b','n')
nnoremap ]] :call searchsyn('\<\%(class\module\)\>','rubyModule\rubyClass','','n')
nnoremap [] :call searchsyn('\','rubyModule\rubyClass','b','n')
nnoremap ][ :call searchsyn('\','rubyModule\rubyClass','','n')
xnoremap [[ :call searchsyn('\<\%(class\module\)\>','rubyModule\rubyClass','b','v')
xnoremap ]] :call searchsyn('\<\%(class\module\)\>','rubyModule\rubyClass','','v')
xnoremap [] :call searchsyn('\','rubyModule\rubyClass','b','v')
xnoremap ][ :call searchsyn('\','rubyModule\rubyClass','','v')
let b:undo_ftplugin = b:undo_ftplugin
\."| sil! exe 'unmap [[' | sil! exe 'unmap ]]' | sil! exe 'unmap []' | sil! exe 'unmap ]['"
\."| sil! exe 'unmap [m' | sil! exe 'unmap ]m' | sil! exe 'unmap [M' | sil! exe 'unmap ]M'"
if maparg('im','n') == ''
onoremap im :call wrap_i('[m',']M')
onoremap am :call wrap_a('[m',']M')
xnoremap im :call wrap_i('[m',']M')
xnoremap am :call wrap_a('[m',']M')
let b:undo_ftplugin = b:undo_ftplugin
\."| sil! exe 'ounmap im' | sil! exe 'ounmap am'"
\."| sil! exe 'xunmap im' | sil! exe 'xunmap am'"
endif
if maparg('iM','n') == ''
onoremap iM :call wrap_i('[[','][')
onoremap aM :call wrap_a('[[','][')
xnoremap iM :call wrap_i('[[','][')
xnoremap aM :call wrap_a('[[','][')
let b:undo_ftplugin = b:undo_ftplugin
\."| sil! exe 'ounmap iM' | sil! exe 'ounmap aM'"
\."| sil! exe 'xunmap iM' | sil! exe 'xunmap aM'"
endif
if maparg("\",'n') == ''
nnoremap :exe v:count1."tag =RubyCursorIdentifier()"
nnoremap g :exe "tjump =RubyCursorIdentifier()"
nnoremap g] :exe "tselect =RubyCursorIdentifier()"
nnoremap ] :exe v:count1."stag =RubyCursorIdentifier()"
nnoremap :exe v:count1."stag =RubyCursorIdentifier()"
nnoremap g :exe "stjump =RubyCursorIdentifier()"
nnoremap g] :exe "stselect =RubyCursorIdentifier()"
nnoremap } :exe "ptag =RubyCursorIdentifier()"
nnoremap g} :exe "ptjump =RubyCursorIdentifier()"
let b:undo_ftplugin = b:undo_ftplugin
\."| sil! exe 'nunmap '| sil! exe 'nunmap g'| sil! exe 'nunmap g]'"
\."| sil! exe 'nunmap ]'| sil! exe 'nunmap '"
\."| sil! exe 'nunmap g'| sil! exe 'nunmap g]'"
\."| sil! exe 'nunmap }'| sil! exe 'nunmap g}'"
endif
if maparg("gf",'n') == ''
" By using findfile() rather than gf's normal behavior, we prevent
" erroneously editing a directory.
nnoremap