Meet the dot command
. repeats your last change, like a rubber stamp: ink it once with a change, then stamp it anywhere.
Day four, 8:50 a.m. The price migration starts today. Before any new price can go in, the new menu service needs forty lines across the menu files brought into its format, each with one small, repetitive fix.
You could make each fix by hand, forty times. Or you could make it once and let the smallest key on the keyboard do the other thirty-nine.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Ink once, stamp anywhere
Every Byte Burrito bag gets its logo from one rubber stamp: ink it once, then stamp, stamp, stamp. . is that stamp. Make a change once, and that inks it. Then press . wherever the cursor is, and Vim makes the same change there.
export interface MenuItem { id: string; name: string; price: number;}export interface MenuItem { readonly id: string; name: string; price: number;}export interface MenuItem { readonly id: string; readonly name: string; price: number;}export interface MenuItem { readonly id: string; readonly name: string; readonly price: number;}readonly, Esc), then every j . stamps the next line.Stamp it
The new menu service wants every field readonly. Ink the stamp on the first field with I, then j . down the rest.
This exercise needs a keyboard. Read on, and play it at your computer.
One change, one stamp
The stamp holds exactly one change. Everything from entering Insert mode to pressing Esc counts as one, however much you typed, and so does a single command like x. Make a different change and you have a new stamp: . always repeats the last one.
What did you ink?
You press A, type ;, press Esc, then j and .. What happens on line 2?
Drop the dollar signs
The new service adds the currency itself, so the $ in each old price has to go. Get to the first one, x it, then stamp the rest.
This exercise needs a keyboard. Read on, and play it at your computer.
A stamp in the wrong place
The stamp always holds your last change, so check what you inked last before you stamp. Stamped the wrong thing somewhere? The undo button from your first morning, u, lifts the last change off again: one u, one stamp.
Which stamp is inked?
TIP has a doubled ;, so you x the extra one. Then you press j and ., hoping to add a ; to FEE. What happens?
Lift the wrong stamp
That just happened in prices.ts. Take the wrong stamp back with u, then ink the right one and stamp it on the next line.
This exercise needs a keyboard. Read on, and play it at your computer.
Semicolon runs
Before it was switched off, the Formatter took the semicolons off whole runs of lines in files nobody had checked yet. Fix the first line of each run with A, then stamp your way down.
This exercise needs a keyboard. Read on, and play it at your computer.
Stamp, from memory
Read the situation, press the keys.
Price stamp
Four runs of lines across the codebase, each missing its semicolons. Ink once per run, then stamp. A clock times the run for your own records.
Stuck? Show a hint
first line of a run: A;<Esc> · each line after: j.This exercise needs a keyboard. Read on, and play it at your computer.
Currency day
The last file before the menu service will start: three different changes, each needed four times. Ink a stamp, use it, ink the next. Semicolons on the Order fields, no $ in the old prices, and export in front of the four constants.
Stuck? Show a hint
A;<Esc> then j. j. j. · x then j. j. j. · Iexport <Esc> then j. j. j.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.
Stamp forever
Endless runs of lines that lost their semicolons, in bigger batches as you go. One A each, then stamps.
This exercise needs a keyboard. Read on, and play it at your computer.