Macros over ranges
Instead of a count, give the card a list of lines: :2,$normal␣@a↵ cooks it on a range, from a highlight : fills in the highlighted lines, and :g/pattern/normal␣@a↵ only on lines that match.
Monday, 3:30 p.m. The real export: 500 rows, and the accountant has typed TOTAL lines by hand in the middle of them, which must stay exactly as they are. A count would cook straight through them.
Instead of a count, hand the card over with a list of lines to cook it on.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Cook it on these lines
:normal runs Normal-mode keys on every line of a range, starting each one at the beginning of its line. So :2,$normal␣@a↵ cooks card a once on every line from line 2 to the last: no count to guess, and no j needed on the card, because each line starts fresh.
| Part | What it says |
|---|---|
:2,$ | which lines: from line 2 to the last (% would be every line) |
normal | what to do on each: go to the start of the line and press these Normal-mode keys |
@a | the keys: cook card a |
Two ways to say how often
A count and a range divide the work differently. With 4@a, the card has to move itself on: it ends with j, and you count the lines. With a range, Vim moves to each line for you, so the card leaves out the j, and you only say which lines. (This is a preview: the Ex track does ranges properly.)
al-pastorveggiebirriapollo"al-pastor",veggiebirriapollo"al-pastor","veggie","birria","pollo",Every line from 2
Quote every item with a comma after it. Write the card on the first line, then :2,$normal␣@a↵.
This exercise needs a keyboard. Read on, and play it at your computer.
Cooked twice
You write the card on line 1 (A ;), then cook it on the whole file with :%normal␣@a↵. What does line 1 say?
On a highlight
Highlight some lines and press :: Vim fills in '<,'>, which means the highlighted lines. Then normal @a and ↵ cooks the card on just those.
Just these
Only the three items get a ;, not the notes around them. Write the card on al-pastor, then j, highlight that line and the next with Vj, and :normal␣@a↵.
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.
Only the lines that match
:g/pattern/normal␣@a↵ cooks the card on every line that matches the pattern, and skips the rest. The export's order rows start with a digit and the TOTAL lines don't, so :g/^\d/normal @a touches only the orders. (Track 12 shows everything :g can do.)
Which lines?
Before you hand over the real card, a small test: :g/^\d/normal␣A;↵. ^\d means a digit at the start of the line. Which lines get a ;?
Around the totals
Turn the order rows into objects and leave the TOTAL lines alone. Write the card on the first row (no j), then :g/^\d/normal␣@a↵. The row you wrote it on no longer starts with a digit, so it isn't cooked twice.
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.
Lists for the kitchen, from memory
Press the keys.