18 Feb 2013

Executing Ruby from Vim

Want to run a Ruby script in Vim? Maybe you’re testing a little commandline snippet. Maybe you want to run a quick query against a webpage. Maybe it’s none of my business why you want to run the Ruby script!

Well here’s a little selection of my Vimscript that accomplishes just that:

Typing your leader key (mapped to “ by default but remapped to ‘,’ by you, right? ) and hitting ‘rr’ in quick sequence will execute the current file using your Ruby interpreter. If you’re using RVM to manage your Rubies, you might also want to consider adding the vim-rvm extension to use the ‘correct’ Ruby.