Skip to content

Commit 3339278

Browse files
committed
ruby mappings
1 parent 1ad4c67 commit 3339278

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

ChangeLog

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
2007-05-06 Tim Pope <[email protected]>
22

3-
* ftplugin/eruby.vim, syntax/eruby.vim: added a default suptype option
4-

3+
* ftplugin/ruby.vim: maps for [[, ]], [], ][, [m, ]m, [M, ]M
4+
5+
2007-05-06 Tim Pope <[email protected]>
6+
7+
* ftplugin/eruby.vim, syntax/eruby.vim: added a default subtype option
8+
59
2007-05-06 Tim Pope <[email protected]>
610

711
* syntax/ruby.vim: Highlight punctuation variables in string

ftplugin/ruby.vim

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,26 @@ if has("gui_win32") && !exists("b:browsefilter")
9696
endif
9797

9898
let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< kp<"
99-
\ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
100-
\ "| if exists('&ofu') && has('ruby') | setl ofu< | endif"
101-
\ "| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
99+
\."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
100+
\."| if exists('&ofu') && has('ruby') | setl ofu< | endif"
101+
\."| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
102+
103+
if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
104+
105+
noremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b')<CR>
106+
noremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','')<CR>
107+
noremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b')<CR>
108+
noremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','')<CR>
109+
110+
noremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b')<CR>
111+
noremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','')<CR>
112+
noremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b')<CR>
113+
noremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','')<CR>
114+
115+
let b:undo_ftplugin = b:undo_ftplugin
116+
\."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
117+
\."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
118+
endif
102119

103120
let &cpo = s:cpo_save
104121
unlet s:cpo_save
@@ -157,6 +174,28 @@ function! RubyBalloonexpr()
157174
endif
158175
endfunction
159176

177+
function! s:searchsyn(pattern,syn,flags)
178+
norm! m'
179+
let i = 0
180+
let cnt = v:count ? v:count : 1
181+
while i < cnt
182+
let i = i + 1
183+
let line = line('.')
184+
let col = col('.')
185+
let pos = search(a:pattern,'W'.a:flags)
186+
while pos != 0 && s:synname() !~# a:syn
187+
let pos = search(a:pattern,'W'.a:flags)
188+
endwhile
189+
if pos == 0
190+
call cursor(line,col)
191+
return
192+
endif
193+
endwhile
194+
endfunction
195+
196+
function! s:synname()
197+
return synIDattr(synID(line('.'),col('.'),0),'name')
198+
endfunction
160199

161200
"
162201
" Instructions for enabling "matchit" support:

0 commit comments

Comments
 (0)