Make replay robust
The technique
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 31The server runs as an ES module now. Turn the six require lines into import lines, like import express from "express";.
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}`));