Learn Practice Daily golf Reference
Macros·Lesson 1 of 5·8 min·0/7 exercisesPro

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.

Scene

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.

From memory

Warm-up from earlier chapters

Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.

Copy this line to the system clipboard.
press the keys…4 keys
1 of 2
Copy this line to the system clipboard.

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.

Before
2201,al-pastor
2202,veggie
2203,birria
2204,pollo
qaI{ id: Escf,a item: "EscA" },Escjq
{ id: 2201, item: "al-pastor" },
2202,veggie
2203,birria
2204,pollo
@a
{ id: 2201, item: "al-pastor" },
{ id: 2202, item: "veggie" },
2203,birria
2204,pollo
@a
{ id: 2201, item: "al-pastor" },
{ id: 2202, item: "veggie" },
{ id: 2203, item: "birria" },
2204,pollo
Write the card on the first row (ending with j onto the next), then @a cooks it on each row after.

End 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.

Try it

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.

Fix the marked spots · 5 left
1al-pastor,
1veggie,
2birria,
3pollo,
4tinga,
NORMALLoading the editor…0.0s1:1

This exercise needs a keyboard. Read on, and play it at your computer.

AfterqaI{ id: Escf,a item: "EscA" },Escjq
"aI{ id: <Esc>f,a item: "<Esc>A" },<Esc>j
The card is just the keys, kept in jar a on the same shelf as your yanks.
Try it

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.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

The sample runFinish the exercise above to see it.
Check yourself

What does the card say?

1a
1b
2c
3d
NORMAL
Keys pressed: qaA;Escjq2@a

You press qa, A, ;, Esc, j, q, and then 2@a. Which lines end in ;?

Pick an answer (or press its number), then watch the engine prove it.
Try it

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
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

From memory

Cards, from memory

Press the keys.

Start writing a card into jar q.
scroll here, then press the keys2 keys
1 of 4
Start writing a card into jar q.
Challenge

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
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

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.

Endless

Lists, endlessly

Endless lists, one card each.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.