artathack.com

about web and mobile development

Run Ruby Scripts Within VIM!

Since I’m writing lots of Ruby scripts lately I was tired testing them using the Command Line and MacVim.

Saving the file, go to to terminal, reuse last command $ ruby foobar.rb

to slow and boring!!!

Fortunately I found out it is possible to run Ruby Scripts inside VIM with the following 2 commands:

1
2
3
:set makeprg=ruby\ %

:make

If you are lazy like me put something like this in your .vimrc and run your scripts blazingly fast (3 keystrokes)!

1
map <Leader>rr :set makeprg=ruby\ %<cr>:make<cr>

If you use RVM and want to use a specific version of your installed rubies you can go with something like this:

1
map <Leader>rr :set makeprg=~/.rvm/bin/ruby-1.9.3-p194\ %<cr>:make<cr>

Of course this works with other scripting languages as well e.g.:

1
map <Leader>rp :set makeprg=python\ %<cr>:make<cr>

Comments