Launching irb from vim

You can run irb from vim with the command !irb.

Running !irb -r % should run the current file in irb then leave irb open. Unfortunately ruby 1.9.2 removed the current directory from the load path which causes this to fail. You could construct a path but it is easier to add the current directory back in, especially if you are using irbtools which does it for you.

Once irbtools are installed add:

map <F2> <ESC>:w<CR>:!irb -r %<CR>

to .vimrc.local which will write then load the current file into irb.

Edit: I was getting some weirdness with the irb prompt with irbtools so I have removed it and added

$: << ‘.’  if RUBY_VERSION >= ‘1.9.2’

to my .irbrc file to add the current directory to the load path.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.