Record, stop and replay

0 of 1

The technique

Your textVim mode: Normal
Wrap both values in Number( and ). Before: min: get(min), / sort: name, / max: get(max),. After: min: Number(get(min)), / sort: name, / max: Number(get(max)),.

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 27

Prices and the page number arrive as strings. Wrap the values of minPrice, maxPrice and page in Number(…).

Your textVim mode: Normal

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"),
  };
}

Yours

Par

Keyboard shortcuts
Ctrl+Enter
Check the result
Ctrl+Alt+U
Undo the last change
Ctrl+Alt+H
Show the next hint
Ctrl+Alt+R
Start the exercise over
Ctrl+Alt+P
Previous exercise
Ctrl+Alt+N
Next exercise
Ctrl+Alt+K⌃⌥K
Show the keyboard shortcuts
Ctrl+Alt+F⌃⌥F
Turn focus mode on or off
Ctrl+Alt+S⌃⌥S
Open the editor settings
Enter
Go on to the next step after you finish

The Ctrl+Alt shortcuts don't clash with Vim's own keys. On a Mac, use Control and Option.