Reputation: 2500
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?
Upvotes: 32
Views: 6937
Reputation: 127
I found this plugin while searching for the answer on the same problem it works for basic ruby code, but I didn't test it out for Rspec etc.
Just install it via pathogen and add let g:hl_matchit_enable_on_vim_startup = 1
https://github.com/vimtaku/hl_matchit.vim
Upvotes: 2
Reputation: 4014
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.
Upvotes: 18
Reputation: 8617
VIM (until 7.2) can't highlight a closing 'if/end' pairs because the matching settings accepts a single character (see :help matchpairs). I recommend using folding instead, provided that you accurately indent your code:
:set foldmethod=indent
Then use: zc
, za
to make sure you're in the right block.
Upvotes: 10
Reputation: 27747
Looks like this vim plugin does paren-matching: http://vimdoc.sourceforge.net/htmldoc/pi_paren.html you could probably dig into that code to see how to extend it to matching other things.
Upvotes: 2