Record, stop and replay
The technique
Each line needs two changes, so the dot can't repeat them. The macro starts with ^ so it works wherever you are on the line. @@ would play it again.
Keys in this lesson
- qa
- Record a macro into register a. Press q to stop.
- @a
- Play macro a.
- @@
- Play the last macro again.
Before this lesson: Insertion, positioning and repetition.
More about this lesson
Record a macro, remember that recording already made one edit, then replay it.
qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.
Example
To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.
Use Start over to try again.
Guides on this topic
Exercise 1 of 1
0keys
par 27Prices and the page number arrive as strings. Wrap the values of minPrice, maxPrice and page in Number(…).
Make it look like this
// Query parameters arrive as strings. This turns them into the filters the API expects. export function readFilters(params) { return { category: params.get("category"), minPrice: Number(params.get("min")), brand: params.get("brand"), maxPrice: Number(params.get("max")), sort: params.get("sort") ?? "newest", color: params.get("color"), page: Number(params.get("page")), inStock: params.has("in-stock"), }; }