Record and replay
A macro is a recipe card in a jar: qa writes down every key you press until q, and @a cooks from it again; end on the next line and 4@a does four more.
Monday, 11:10 a.m. The new ordering system wants last quarter's 500 orders as objects, not CSV rows: 2201,al-pastor has to become { id: 2201, item: "al-pastor" },. That's the same handful of edits on every line, five hundred times, by tomorrow morning. Before the real run, you'll get the edits right on a small sample.
The stamp, ., repeats one change. You need a whole recipe repeated.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Write the recipe card
qa starts writing a recipe card and files it in jar a on the shelf. Every key you press from now on goes on the card, and you do the job once, by hand, as usual. q stops writing. Then @a cooks from the card: Vim replays every key on it, exactly as you pressed them.
2201,al-pastor2202,veggie2203,birria2204,pollo{ id: 2201, item: "al-pastor" },2202,veggie2203,birria2204,pollo{ id: 2201, item: "al-pastor" },{ id: 2202, item: "veggie" },2203,birria2204,pollo{ id: 2201, item: "al-pastor" },{ id: 2202, item: "veggie" },{ id: 2203, item: "birria" },2204,polloEnd on the next line
The card above ends with j: the last step moves to the next row, so each time you cook from it, you're ready for the next one. That makes a count work: 4@a cooks four times in a row. @@ cooks the last card again, handy for one more.
A tiny card
Start small: each item needs a comma at the end. qa, A and ,, Esc, j, q. Then 4@a for the other four.
This exercise needs a keyboard. Read on, and play it at your computer.
I{ id: <Esc>f,a item: "<Esc>A" },<Esc>ja on the same shelf as your yanks.Five rows
Record the first row into jar a: qa, then I and { id: (with a space at the end), Esc, f,, a and item: " (a space first), Esc, A and " },, Esc, j, q. Then 4@a for the other four.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
What does the card say?
You press qa, A, ;, Esc, j, q, and then 2@a. Which lines end in ;?
Practice lists
Lists where every line needs the same edit, and this time nobody tells you the steps: look at what the first line needs, write the card on it, end with j, then cook it with a count.
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Cards, from memory
Press the keys.
Lists
Four lists to reformat: quotes, calls, rows to objects. One card each, and test before you scale: after writing the card, cook it once with @a and look at the line it changed. Then the count for the rest.
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis 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.
Lists, endlessly
Endless lists, one card each.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.