Robust macros
Write cards that work on every line: start from a known place (0, I, A), move by what's always there (f, not 5x), end on the next line, and let a failing step stop a too-big count.
Monday, 1:30 p.m. The refunds export, after your quick 5x card: fine for 36 rows, then from row 37, where the ids go from four digits to five, every row keeps a comma it should have lost.
A card written on the first row only has to work for the first row. Yours has to work for all of them.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Steps that are true everywhere
Write the card so it works on any order, not just the first: no "five steps along", only steps that are true on every line. Move by what's always there: df, deletes up to and including the comma, however long the id. f, t, $, I and A find their place on any line; 5x, 3l and 2w only on lines like the first.
1003,veggie,110021,pollo,11022,tinga,2veggie,110021,pollo,11022,tinga,2veggie,1,pollo,11022,tinga,21003,veggie,110021,pollo,11022,tinga,2veggie,110021,pollo,11022,tinga,2veggie,1pollo,11022,tinga,2Ids of any length
Drop the id column from every row, with ids from three to six digits long. A card with df, and j, then a count.
This exercise needs a keyboard. Read on, and play it at your computer.
Start at the stove
The card also starts wherever you happen to be. If the cursor is in the middle of the first row when you start writing, df, deletes from there, and j carries that column down to the next row. Make the first step put you somewhere known: 0 (or ^, I, A). Then it doesn't matter where you were.
From the middle
Same job, but the cursor starts in the middle of the first row. Begin the card with 0.
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.
A step that fails stops the cooking
When a step on the card can't be done (an f, on a line with no comma, a j on the last line), Vim stops cooking at once, count and all. So with a card that ends in j, 99@a on a list of 30 lines stops when j runs out of lines. It also means one odd line in the middle stops the whole run there.
Where does it stop?
The card is 0 f, x j, written on the first line. Then 9@a. Which lines lose their comma?
Stopped halfway
A note sits in the middle of the refunds, with no comma. Write the card (qa 0 df, j q) and cook it with 99@a: it stops on the note, which is what you want. Then j past the note and 99@a again.
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.
A card that doesn't stop
A big count is safe only when the card fails exactly where the job ends. Some lines don't fail; they just get the wrong edit. A row someone already fixed by hand still has a comma, so df, happily takes its item name next. On a list like that, count exactly, or stop the run before the row.
Already done
The last row was done by hand already. The card is 0 df, j, written on the first row, then 9@a. What does the list say?
Robust cards, from memory
Press the keys.
Four odd lists
Four refunds lists, and in each one something isn't like the first row. Look before you write the card: where will it stop, and is that where the job ends? Test it once on the second row, run it, and check the last line.
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.