Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Highlight keyword pairs in Ruby (def/end, do/end, etc)

Tags:

vim

ruby

macvim

In one of the Eclipse-based editors that I tried out recently (I think it was RubyMine), when a Ruby keyword that either opened or closed a method or block was selected, the corresponding open/close keyword was highlighted. Similar to the way that Vim is able to highlight a corresponding open/close parenthesis.

For instance, if I selected a 'def', it would highlight the corresponding 'end'. It also worked for do/end blocks.

This was really handy, especially for those long and sometimes heavily nested Rspec files.

Does anybody know how to achieve this in Vim?

like image 837
pakeha Avatar asked Aug 05 '10 09:08

pakeha


1 Answers

If you are using Vim 7.3, you should have the MatchIt vim macro available.

Add runtime macros/matchit.vim to your .vimrc file and you should be able to use % to match the ruby blocks.

You can look at the filetype plugin for ruby to see what it will move between.

like image 118
deterb Avatar answered Sep 17 '22 07:09

deterb