xref: /vim-8.2.3635/runtime/ftplugin/ruby.vim (revision 9e54a0e7)
1" Vim filetype plugin
2" Language:	Ruby
3" Maintainer:	Gavin Sinclair <gsinclair at soyabean.com.au>
4" Info:		$Id$
5" URL:		http://vim-ruby.rubyforge.org
6" Anon CVS:	See above site
7" ----------------------------------------------------------------------------
8"
9" Original matchit support thanks to Ned Konz.	See his ftplugin/ruby.vim at
10"   http://bike-nomad.com/vim/ruby.vim.
11" ----------------------------------------------------------------------------
12
13" Only do this when not done yet for this buffer
14if (exists("b:did_ftplugin"))
15  finish
16endif
17let b:did_ftplugin = 1
18
19let s:cpo_save = &cpo
20set cpo&vim
21
22" Matchit support
23if exists("loaded_matchit") && !exists("b:match_words")
24  let b:match_ignorecase = 0
25
26 " TODO: improve optional do loops
27 let b:match_words =
28    \ '\%(' .
29    \	  '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
30    \	'\|' .
31    \	  '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
32    \ '\)' .
33    \ ':' .
34    \ '\%(' .
35    \	  '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
36    \	'\|' .
37    \	  '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
38    \ '\)' .
39    \ ':' .
40    \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>'
41
42  let b:match_skip =
43     \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
44     \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
45     \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
46
47endif
48
49setlocal formatoptions-=t formatoptions+=croql
50
51setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
52setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
53setlocal suffixesadd=.rb
54setlocal omnifunc=rubycomplete#Complete
55
56" TODO:
57"setlocal define=^\\s*def
58
59setlocal comments=:#
60setlocal commentstring=#\ %s
61
62if !exists("s:rubypath")
63  if executable("ruby")
64    let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
65    if &shellxquote == "'"
66      let s:rubypath = system('ruby -e "' . s:code . '"')
67    else
68      let s:rubypath = system("ruby -e '" . s:code . "'")
69    endif
70    let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
71  else
72    " If we can't call ruby to get its path, just default to using the
73    " current directory and the directory of the current file.
74    let s:rubypath = ".,,"
75  endif
76endif
77
78let &l:path = s:rubypath
79
80if has("gui_win32") && !exists("b:browsefilter")
81  let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
82		     \ "All Files (*.*)\t*.*\n"
83endif
84
85let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
86      \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
87
88let &cpo = s:cpo_save
89unlet s:cpo_save
90
91"
92" Instructions for enabling "matchit" support:
93"
94" 1. Look for the latest "matchit" plugin at
95"
96"	  http://www.vim.org/scripts/script.php?script_id=39
97"
98"    It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
99"
100" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
101"
102" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
103"
104" 4. Ensure this file (ftplugin/ruby.vim) is installed.
105"
106" 5. Ensure you have this line in your $HOME/.vimrc:
107"	  filetype plugin on
108"
109" 6. Restart Vim and create the matchit documentation:
110"
111"	  :helptags ~/.vim/doc
112"
113"    Now you can do ":help matchit", and you should be able to use "%" on Ruby
114"    keywords.	Try ":echo b:match_words" to be sure.
115"
116" Thanks to Mark J. Reed for the instructions.	See ":help vimrc" for the
117" locations of plugin directories, etc., as there are several options, and it
118" differs on Windows.  Email [email protected] if you need help.
119"
120
121" vim: nowrap sw=2 sts=2 ts=8 ff=unix:
122