Drill 1: Jumps

The inaugural post to this series will start simply. This week's tip is not the most amazing, but it provides an excellent start to practice with.


What I want is to promote everybody to be more concious of their Vim usage as they do their day to day work. I don't need to you to stop and focus on training. Your boss wouldn't like it if you didn't get much done because you were playing with a text editor. Instead what I ask is that you are consciously practicing your editing as you do your work. Make use of this one command when you see the opportunity. In fact, force yourself to use it. If you find yourself already finished with a sequence you could have done better, undo it, shift yourself back and do it again, but "correctly". Quickly enough this will become second nature.

We will end up spending several (many!) posts on the topic of jumps, since it is so core to editing text. As programmers, we spend so much time moving around, and so little time actually typing in new code. So learning the best way to move around seems like a noble goal for our first go-around.

This Week's Drill

Vim offers so many ways to move up and down in a file. To designated points, or unknown destinations. The simplest is of course j and k, moving up and down a line at a time.

But that's tiring! You can repeat the command like 5j to go down 5 lines at once. But counting is hard to get right (and boring!). Make the computer do all the work! Just jump down to the next section.

Well... now we need to start defining what a section is. Vim has many ways, but my first go-to option is "the next blank line". It lines up nicely with most of my Ruby method definitions (short & sweet!). It jumps paragraphs at a time in my markdown files, and is generally close-enough to what I'm looking for that it works for me.

} goes forward to the next blank line

{ goes backwards to the previous blank line

To remember, they point their sharp bit in the direction they'll move.

The role that the curly braces use in my navigation is twofold. Sometimes, I know something is near, but I'm not sure exactly what I need. { and } do an excellent job of idly skimming a file to find what you're looking for.

The other use I have found for { and } is to jump a method or two down. This is actually suboptimal, and will be something I'll be practicing in the next week or two, as I share more tips.


Next week we'll talk about other ways to jump around.

I'd love to hear from your practice. What do you want to get better at? Normal mode? Command Mode? Insert Mode Tricks?

Email me at chris@vimdrills.com.


comments powered by Disqus