Find and replace by hand
* lines up every copy of the word under the cursor; fix one, then n . the rest, or let cgn bring each match to you.
4:05 p.m. The photo of the specials board has forty likes and one comment: "tortila?" It's misspelled nine times across the menu files. Two of those sit inside quoted five-star reviews, and marketing wants those word for word, typo and all.
So no blind find-and-replace. You want to visit each one, decide, and fix it in two keys.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
More like this
Put the cursor on a word and press *: Vim reads it as more like this and jumps to the next copy of that word. n slides on to the copy after that, and at the end of the file it wraps round to the top. It's the third slide for your packing line, after j and ;.
tortila.size > 0 && wrap(tortila, tortila.filling);tortila jumps to the next copy, and n to the one after.Which copies count?
The cursor is on count. You press *. Where does it land?
Change once, then slide and stamp
ciw changes the word under the cursor, from anywhere in it. Take it as a recipe for now: it reads change inner word, and the next track takes it apart. So: * to line up the copies, ciw and the right spelling to ink the stamp, then n ., n .. The dot formula, with n as the slide.
const qty = item.qty;return price * qty;const qty = item.quantity;return price * qty;const qty = item.quantity;return price * quantity;const quantity = item.quantity;return price * quantity;qty, ciw renames it, and each n . renames the next one, wrapping back to the first.Fix the spelling
One name is misspelled everywhere it appears. Get onto one copy, *, fix it with ciw, then n . until they all match.
This exercise needs a keyboard. Read on, and play it at your computer.
Let one go by
On the packing line you can let a bag slide past unstamped. Here that's one more n: n lands on the copy you want to keep, n again moves past it, and you stamp the next. You decide at every stop.
Keep the review
Fix every tortila except the one in the quoted review. The cursor starts on the first one.
This exercise needs a keyboard. Read on, and play it at your computer.
The conveyor
cgn is a second recipe: it changes the match under the cursor, or the next one if you're not on a match, so the slide is built into the change. Ink it once, and from then on . alone brings the next copy to you and stamps it, like a conveyor belt. Want to keep one? n lands on it, n again slides past, then ..
Rename with the conveyor
The new menu service calls it quantity. The cursor is on qty: *, cgn once, then let . do the rest.
This exercise needs a keyboard. Read on, and play it at your computer.
More like this, from memory
Read the situation, press the keys.
Spellcheck sprint
Three files, one misspelled name in each. Every copy of it should match the spelling the rest of the file expects.
Stuck? Show a hint
on a copy: *, ciw and the right name, <Esc>, then n. for each copy (or cgn and .)This exercise needs a keyboard. Read on, and play it at your computer.
Rename the special
sides.ts: seven copies of tortila. The five outside the two quoted reviews become tortilla; the reviews stay exactly as written. The cursor starts on the copy in chips. Pick your slide.
Stuck? Show a hint
*, cgntortilla<Esc>, then . for each copy · n n lets a review go by (or ciw and n . to look at each first)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.
Proofreader on call
Endless repairs, each wanting a different slide: a misspelled name (n .), a run of lost semicolons (j .), squeezed operators (; .). Look first, then pick the slide.
This exercise needs a keyboard. Read on, and play it at your computer.