xref: /vim-8.2.3635/runtime/ftplugin/ruby.vim (revision a5792f58)
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
54
55" TODO:
56"setlocal define=^\\s*def
57
58setlocal comments=:#
59setlocal commentstring=#\ %s
60
61if !exists("s:rubypath")
62  if executable("ruby")
63    let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
64    if &shellxquote == "'"
65      let s:rubypath = system('ruby -e "' . s:code . '"')
66    else
67      let s:rubypath = system("ruby -e '" . s:code . "'")
68    endif
69    let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
70  else
71    " If we can't call ruby to get its path, just default to using the
72    " current directory and the directory of the current file.
73    let s:rubypath = ".,,"
74  endif
75endif
76
77let &l:path = s:rubypath
78
79if has("gui_win32") && !exists("b:browsefilter")
80  let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
81		     \ "All Files (*.*)\t*.*\n"
82endif
83
84let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
85      \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
86
87let &cpo = s:cpo_save
88unlet s:cpo_save
89
90"
91" Instructions for enabling "matchit" support:
92"
93" 1. Look for the latest "matchit" plugin at
94"
95"	  http://www.vim.org/scripts/script.php?script_id=39
96"
97"    It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
98"
99" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
100"
101" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
102"
103" 4. Ensure this file (ftplugin/ruby.vim) is installed.
104"
105" 5. Ensure you have this line in your $HOME/.vimrc:
106"	  filetype plugin on
107"
108" 6. Restart Vim and create the matchit documentation:
109"
110"	  :helptags ~/.vim/doc
111"
112"    Now you can do ":help matchit", and you should be able to use "%" on Ruby
113"    keywords.	Try ":echo b:match_words" to be sure.
114"
115" Thanks to Mark J. Reed for the instructions.	See ":help vimrc" for the
116" locations of plugin directories, etc., as there are several options, and it
117" differs on Windows.  Email [email protected] if you need help.
118"
119
120" vim: nowrap sw=2 sts=2 ts=8 ff=unix:
121