Act, repeat, reverse
; and n each have a partner that goes back the other way, , and N, so overshoot freely. A change doesn't travel; u takes it back.
4:45 p.m. On your way to the order form you search for qty, press n, n, n, and sail one past the line you wanted. Going all the way round the file again would take a dozen presses.
Remember the remote from day one? Look closer: the buttons come in pairs.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Every button has a partner
On a remote, next to the button that skips forward sits one that skips back. Vim's travel keys work the same way: ; and n each have a partner that goes the other way. So repeat freely. If you go one too far, one press of the partner brings you back.
| You want to | Act | Repeat | Reverse |
|---|---|---|---|
| find a character on the line | f t F T | ; | , |
| find the word under the cursor | * # | n | N |
The comma skips back
You met the first pair on day two: ; skips on to the next copy of the character you found, in the same direction, and , skips back the other way. Overshot by one comma? ,, and you're there.
One too far
You wanted the comma after c. You pressed f,, then ; three times: one too many. Now you press ,. Where are you?
Back one
Targets on the line, some just behind where your last find left you. When the target is one copy back, , is the cheapest way there.
This exercise needs a keyboard. Read on, and play it at your computer.
n and N
The search buttons pair up the same way. n repeats your last search in the same direction and N goes the other way: after * that's down and up the file, after # it flips. So after a * that went one too far, the order form is one N away.
Both directions
Each target is a word you can line up with * or #. Then n and N skip forward and back through its copies.
This exercise needs a keyboard. Read on, and play it at your computer.
Changes don't travel
Changes are different. . doesn't go anywhere: it makes the change again where you stand, so there's no other way to press. What a change has is a way back: u takes the last one off, as it did with this morning's wrong stamp. Stamped one copy too many? u, then let n carry you past it. The next lesson looks at undo properly.
One stamp too many
The order form is renaming cnt to count, but the kitchen's note quotes cnt and has to stay as written. Your last n . wrapped round to the top and stamped the quote. Take that stamp back, then fix the copy that's left.
This exercise needs a keyboard. Read on, and play it at your computer.
Find the partner
Read the situation, press the key.
Overshoot recovery
Twelve stops across the order code. Finds, searches, and their partners: whichever reaches each stop in the fewest keys, forwards or back.
This exercise needs a keyboard. Read on, and play it at your computer.
Extra practice optional
The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.
Both ways, forever
Endless stops. Forward or back, find or search: pick the pair that gets there first.
This exercise needs a keyboard. Read on, and play it at your computer.