Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to jump from do to end of a Ruby block using Vim?

Tags:

vim

ruby

I'm using vim for ruby, php and perl development. There is the shortcut % to jump from the begin of a block (subroutine/function/method/if) to the end and vice versa. For me a % on a do/end tag in ruby doesn't work.

How can I do that with vim?

like image 787
gustavgans Avatar asked Oct 27 '09 09:10

gustavgans


2 Answers

The matchit plugin allows matching more than just parentheses and comments. A ruby version can be found here.

like image 118
soulmerge Avatar answered Nov 05 '22 21:11

soulmerge


with the matchit plugin and this code in ~/.vim/ftplugin/ruby.vim it works now :)

" Matchit support:
if exists("loaded_matchit")
  if !exists("b:match_words")
    let b:match_ignorecase = 0
    let b:match_words =
\ '\%(\%(\%(^\|[;=]\)\s*\)\@<=\%(class\|module\|while\|begin\|until\|for\|if\|unless\|def\|case\)\|\<do\)\>:' .
\ '\<\%(else\|elsif\|ensure\|rescue\|when\)\>:\%(^\|[^.]\)\@<=\<end\>'
  endif
endif
like image 7
gustavgans Avatar answered Nov 05 '22 20:11

gustavgans