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:
this is equivalent to running
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:
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
then jump back to the class being tested (say FooController), make your changes then hit
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
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.