life.i.think: Ruby/RHTML Jump (%) in VIM

Ruby/RHTML Jump (%) in VIM
Scribbled on November 5th. 1 comment.

If you use VIM, you’re probably familiar with the incredible % command. It allows you to jump back and forth between opening and closing block operators, for example {} [] ().

Unfortunately, the default doesn’t support HTML, and subsequently RHTML tags.

Thank god for matchit!

From ~/, create a .vim directory (if it doesn't already exist), and extract matchit.zip.

Matchit should be up and running for a number of additional languages (ADA, HTML, etc). Now we just need to associate RHTML files with the proper type (HTML).

Then in ~/.vim, create a file called filetype.vim with the following content:
augroup filetypedetect
  au! BufRead,BufNewFile *.rhtml setfiletype xhtml
augroup END


You can now place your cursor at the beginning of a <% ... %> block and hit %. Tada! (This also provides the added benefit of HTML snytax highlighting)


	

UPDATE: The VIM-Ruby project includes matchit definitions for .rb files which allow you to jump between def/end declarations as well!

Comments

Leave a response

  1. HarveyNovember 11, 2005 @ 12:32 PM

    I use VIM, but I’m more familiar with the infamous; (. )( .) command. It should come as a default upgrade with the ubuntu software package. Check your c:/boobs directory. It allows all the HTML you can throw at it.

Comment