I attended the Driven Software Unconference a few weeks ago which was structured more-or-less according to an Open Space model. One of the less-common technology-focussed topics of discussion was "Vim Tips and Tricks".
Unfortunately "Vim Tips and Tricks" quickly degenerated to an Emacs versus Vim advocacy face-off (as tends to happen when emotions are allowed to take charge). I didn't get to learn much in the way of Vim tips or tricks and at the same time, I didn't get to share some of my own favourite tips/tricks. So ... maintaining the trend of "short-and-sweet sound-byte" that I started last week Friday, here's one of my Vim favourites.
So what makes Vim fundamentally different from other editors (or indeed, other productivity tools)? For me it's the fact that I get to flow, that is ... I get to do work smoothly and quickly. I believe strongly that you need to be master of the tools of your trade; if you work on the technical side of information technology and especially if you're in software development, your primary tool is your text editor of choice. Well ... to be precise, your primary tool is a combination of the software and the hardware–far too often the mechanism to input information into a text editor (mouse and keyboard) is neglected when it comes to mastery.
Along these lines, I'm totally on the same page as Jeff Atwood and Steve Yegge, too many people are quick to hand-wave the importance of touch-typing away, presumably as a result of ... laziness. If you're a software developer or a system administrator who doesn't type without looking at the keyboard then you have no excuse; you're just not doing your vocation justice.
Vim was made for touch-typists, and when I say touch-typists, I'm talking about those folk who spend most of their typing minutes with their fingers as close as possible to the home position. Unfortunately, this is almost impossible to do when you're having to shift a hand off the keyboard to move a mouse pointer, or even if you're having to navigate using the (off-to-the-left) cursor keys.
As well as Vim accommodates touch-typists, there remain some fundamental challenges for us masters of text manipulation, one-of-which is the need to quickly and effectively navigate around a screenful of text. Vim has in-built the facility to specify repeat counts for any command by pre-pending the command with a number, e.g., 10j moves the cursor down ten lines (j being the normal mode command to move one line down). When navigating though, visual cues are key to being effective in using such a facility–Vim also allows lines to be numbered using the number option:
Moving directly to a line then becomes a case of specifying the line to jump to and jumping:
There's an even more powerful way of moving around in Vim though, using the relative numbering facility that's been made availabe in recent versions of Vim:
In this case, lines other than that which the cursor is on are numbered as an offset from the cursor line.
Vim's repeat count facility can then be leveraged to to move directly using a visual cue in a minimum number of keystrokes: