Make replay robust

0 of 1

The technique

Your textVim mode: Normal
Mark four items as reviewed and leave the footer alone. Before: one / two / three / four / footer. After: one [reviewed] / two [reviewed] / three [reviewed] / four [reviewed] / footer.

Recording handled the first item, so three replays finish the rest. A fourth would have changed the footer.

Keys in this lesson

qa
Record a macro into register a. Press q to stop.
3@a
Play macro a three times.

Before this lesson: Record, stop and replay.

More about this lesson

Write a macro that works on lines of different lengths, and replay it only as often as you need.

A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.

Example

If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.

Use Start over to try again.

Guides on this topic

Exercise 1 of 1

0keys

par 31

The server runs as an ES module now. Turn the six require lines into import lines, like import express from "express";.

Your textVim mode: Normal

Make it look like this

import express from "express";
import helmet from "helmet";
import morgan from "morgan";
import { json } from "body-parser";
import ordersRouter from "./routes/orders";
import config from "./config";

const app = express();
app.use(helmet());
app.use(morgan(config.logFormat));
app.use(json({ limit: "1mb" }));
app.use("/orders", ordersRouter);

app.listen(config.port, () => console.log(`API on port ${config.port}`));

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.