Using Vim for Rails development

After I started working fulltime on a Rails application, most of my daily work takes place in a text editor. I decided that this was as good an oppurtunity as any to learn vim properly. I want to list a few useful things that I’ve recently learned.

In my discussions below I’ll often mention the <leader> character. <leader> is bound to \ by default, but your configuration may vary.

Multiple commands at once

You can run multiple commands at once by seperating them with a | (pipe) character. For instance:

:vsp | e somefile

this is equivalent to running


followed by

:e somefile.

The power of plugins

I’ve used vim off and on for a long time, but have only needed the most basic functionality. But there is a wide selection of plugins available that really turn a promising editor into an awesome workbench.


According to its README file, Fugitive “may very well be the best Git wrapper of all time”. The commands that I’ve used the most are:

:Gdiff for a split-pane comparison of my copy vs. the copy in the repository.

:Gread which is equivalent to git checkout, except that it works on the vim buffer instead of reverting the actual file. This means for instance that you can revert your changes by accident and then undo.


NerdCommenter is a powerful plugin that allows you to make all sorts of comments with ease. In my daily use I rely mostly on a single command, namely:

<leader> c <space>

which toggles comments on/off for the current line or for all the lines of a visual selection.


Vroom makes it easy to run your Rails tests within vim. Simply jump to your test (say FooControllerTest), hit

<leader> r

then jump back to the class being tested (say FooController), make your changes then hit

<leader> r

again (without having to jump into the test file).


BufferGator allows you to view a list of active buffers, preview their contents and navigate them. To activate press

<leader> b

Vim Golf

One of the hallmarks of vim is how much you can accomplish using only the keyboard, with most activity taking place on the home row, with very few keystrokes. VimGolf is a fantastic tool for improving your vim chops. The gist of it is that you select a challenge, where you are given a file and an end result. Your goal is to edit the file to look like the end result in as few keystrokes as you can. I highly encourage you to check it out.

4 thoughts on “Using Vim for Rails development

  1. Pingback: Beginning Vim | Transmit

  2. Don’t take it personal, but foigvre me if I’m not impressed by the capabilities of vim. It’s nice I use it to edit small config files, and that’s it.Macros are by no means more powerful in vim. Emacs is Lisp, so if you want to be mindblown by Lisp macros take a look at LOL. In the editor context they’re just glue for the editors builtin functions, so yeah it gets interesting when your editor and the extension language are one and the same. You can’t possibly compare vim script to Lisp, just think at the amount of bindings Lisp has. Heck if you’d want to you can even play with X11 windows, a shell that understands Lisp code and returns lisp data that you can manipulate in any way you want, sockets, framebuffers.

  3. Love vim so much. Great to see you are picking it up. If you haven’t already run across Drew Neil’s vimcasts, I highly recommend them, as well as his book, Practical Vim. It is stellar for intermediate vim users looking to get advanced.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">