I’ve been a vim user for six years, and brought the vim fever to thoughtbot. I
tend to rely more on the built-in commands than on scripts and plugins. My
favorite commands start with f and t (think first and ‘till - see :help f
or :help t):

Finding characters with f and t rocks. For example, if you’re at the
beginning of:

{:foo => 1, :bar => 3, :baz => 8, :barney => -1}

And you want to put a newline after the comma, you can do:

f,a<ENTER>

To jump to the next comma and repeat the prior action you can do:

;.

This is because ; repeats the prior f or t, and . repeats the prior modification.

If you have to do this a lot in a row, you could make a macro from it:

qa0f,a<ENTER><ESC>q

This sets the macro named ’a‘ as: go to the beginning of the line, find the
first comma, and append a newline after it. You can then repeat this macro with
@a and repeat that macro (the one you just did) with @@.

You can also use t and f as a motion for, say, c and d. Like if you’re
at the beginning of:

And you need to change the image source to /images/giant_french_spider.jpg.
It goes like this:

2f/ ct"giant_french_spider.jpg<ESC>

The 2 in front of f finds the second /; the space immediately after moves
to the next character (could also use l (lowercase L) instead). Then change
the text up to (but not including) the doublequote with ct"; type the text and
hit escape to get back to command mode.

Three of my favorite things in Vim are the rails.vim plugin, the ack.vim plugin,
and visual block mode.

The rails.vim plugin does an excellent job of
syntax highlighting, navigating from one file to another (type :help :RT for a
description of how to quickly jump between e.g. models and tests or a controller
action and its view), and a slew of other things.

Getting around in vim is way quicker than just holding down the arrow keys. If
you’re checking a bit of code and moving between it and somewhere else, you
should set a mark. <letter> sets a mark, which you can jump to with
'<letter>. Likewise, jumping to a specific line is as simple as
:<line-number>. Got a failing test on line 146? :146 and you’re there. So
you can set a mark for the line you’re on with ma, jump to line 20 with :20,
fix your typo, then jump back with 'a, and you don’t have to remember exactly
what line you’re on.

Thing is, when you do that, you may find your cursor is at the bottom of the
screen, making further code hard to read. Fix that with z., which will zip the
line the cursor is on to the middle of the window. You can also snap it to the
top (z<ENTER>) or bottom (z-) just as easily.

When you cut a line with d (or yank it with y), the text you paste goes into
a register. You can control the register it goes into by hitting "<letter>
first. For example, "gyy will copy the current line into the g buffer. You
can paste this text back by specifying the register before your p command:
"gp.

If you enjoyed this post, you might also like:

Want to level up your testing game?
Learn about testing Rails applications and TDD
in our new book
Testing Rails.
The book covers each type of test in depth,
intermediate testing concepts,
and anti-patterns that trip up even intermediate developers.