← All 115 books vim macros, one recording per page
One recording per page

vim macros, one recording per page

Thirty lessons on recording vim macros with q into a named register, stopping with q, replaying with @ and @@, counts like 3@q, appending with the uppercase qA, pasting a register out and yanking the fix back in, macros that walk lines with j and start with 0, the macro as plan B beside the dot command, running over a range with :normal and why the bang matters, a macro per :global match, recursive registers that call themselves, register hygiene with :reg, saving takes to a file, one-keystroke undo, and one real recording task per page, from quoting lines to swapping fields and running one register across a whole arglist.


Steve Hodgkiss 8 lessons

One recording, its register, and how to replay it. That's a page.

vim macros, one recording per page

Thirty lessons on recording vim macros with q into a named register, stopping with q, replaying with @ and @@, counts like 3@q, appending with the uppercase qA, pasting a register out and yanking the fix back in, macros that walk lines with j and start with 0, the macro as plan B beside the dot command, running over a range with :normal and why the bang matters, a macro per :global match, recursive registers that call themselves, register hygiene with :reg, saving takes to a file, one-keystroke undo, and one real recording task per page, from quoting lines to swapping fields and running one register across a whole arglist.


Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).

Every fact in this book is as the official source states it, fetched and read during this build: the Vim help files repeat.txt (q recording, the stopping q, @ replay, @@, counted replays, :normal inside :global), motion.txt (the 0 and j motions inside macros), change.txt (CTRL-A on numbers, put and yank), undo.txt (undo blocks, the numbered registers and the dot, the :display command), map.txt (the normal! omap example), the Vim user manual chapter usr_10.txt (record and playback, the #include example, 3@a, the 26 registers, editing a recorded register, appending with an uppercase register), and the Wikipedia article on Vim. Motions, operators, registers as named clipboards and the dot command are assumed from the earlier vim book; no facts are sourced from Reddit, Stack Overflow or tutorials. An independent guide, not affiliated with or endorsed by the Vim project.

Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.

© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.

Edition 1.0 · stevehodgkiss.net

Contents

Contents


Part 1 · The first recording
Record with q4
Part 2 · Macros are registers
Append with qA5
Part 3 · Macros that move
One line per pass6
Part 4 · Macro versus dot
The macro as plan B7
Part 5 · Run it everywhere
:normal over a range8
Part 6 · Recursive macros
Yank the @ line in9
Part 7 · Real recording tasks
Increment the column10
Part 8 · Beyond one buffer
When not to macro11

Per Vim help, repeat.txt: q{0-9a-zA-Z"} records typed characters into the named register, uppercase to append; the Vim user manual usr_10.txt puts the register name between a and z.

vim companion · No. 01
The first recording

Record with q

q, a register, then the work

type q, then a register: recording beginsstart recordingqaq{register}the register is a name from a to z(user manual, usr_10.txt)the status line answers-- RECORDING @a --every key you now type isstored in register a, as textpress q alone to stopq starts the tape, the register names it, the status line confirms it

The dot command repeats one change. When the job is bigger, start a tape: type q, then a register name, a to z. From that keystroke, Vim records everything you type.

The proof sits on the status line: -- RECORDING @a --. It stays there until you stop, so you always know whether your keys are being captured.

Pick a register you do not use for yanks; macros and copied text share the same boxes.

RECORD IT THIS WEEK

Type qa, check the status line says recording, do a little work, then stop with q before anything else.

Per Vim user manual, usr_10.txt: to append to a register use an uppercase letter; qC then a search and Enter then q appends to register c, and the same rule holds for yank and delete.

vim companion · No. 02
Macros are registers

Append with qA

Uppercase continues the take

an uppercase register: the recording continues"a^i-- <Esc>recorded first, with qathen record withqA/TODOthe tail is appended to a"a^i-- <Esc>/TODO<Enter>the full macro nowqA does not replace: it appends, for recording and for yanks alike

Missed a step at the end of the recording? Do not start over: q with the uppercase letter appends. qA adds keys to register a; it never replaces them.

The manual's example records a search onto an existing macro exactly this way. The same case rule governs yanks: "AY adds another line to register a.

Lowercase starts fresh; uppercase continues. One letter of case, two meanings.

RECORD IT THIS WEEK

Record a macro into a, stop, then qA and append a j so it walks lines; check :reg a shows both parts.

Per Vim user manual, usr_10.txt: a count before @ executes the macro that many times; this book's plan matches the count to the lines remaining when each pass ends one line lower.

vim companion · No. 03
Macros that move

One line per pass

Count lines, count replays

one line per pass: count the lines, count the replayspass 1introduction -> fixedpass 2chapter one -> fixedpass 3chapter two -> fixedpass 4summary -> fixed4 lines, so 4@a; a fifth replay would spill past the endthe macro consumes one line per run: match the count to the lines

When the macro ends in j, each replay consumes exactly one line: the count and the remaining lines must match.

Four lines to fix: record on the first, replay with 3. Six lines: replay with 5. The uncounted extra pass runs j past the last line and the macro misfires on whatever it finds below.

Count before you type the count. It is the one number in the whole manoeuvre.

RECORD IT THIS WEEK

Fix a six-line column in one take: record on line one, replay 5@a, and confirm the cursor lands on line seven, clean.

Per Vim user manual, usr_10.txt: command recording exists for work more complex than the single change the dot command can repeat.

vim companion · No. 04
Macro versus dot

The macro as plan B

Plan A dot, plan B record

plan A is the dot; the macro is plan Bone simple change, repeatedthe dot .several changes, repeatedq ... q, then @athe decision,before you touchthe keyboardusr_10.txt: a register can do several changes and move around as wellreach for q the moment the dot cannot hold the whole job

Ask one question before any repetitive edit: is this one change, or several? One, repeated: the dot. Several, repeated: the register.

Plan B kicks in quietly: a change plus a movement plus another change is already past what the dot holds. Record it once and the whole bundle replays.

The dot for one move, q for a plan. Choosing first is faster than either.

RECORD IT THIS WEEK

Catch yourself repeating a two-step edit; classify it as dot work or macro work before the third repetition.

Per Vim help, repeat.txt: :g/pat/normal runs Normal mode commands on the matching lines and the commands must end with a whole command; usr_10.txt points :global at :normal for Normal mode keys.

vim companion · No. 05
Run it everywhere

:normal over a range

One command line, no count

the ex way: a range, one command, no counting:%normal @aevery line in the file, one macro eachline 1 fixedline 2 fixedline 3 fixedno j needed: :normal stepsline by line through the rangeranges: 5,12 .,$ %usr_10.txt teaches ranges before :global:%normal @a: the macro runs on every line, and you type it once

The ex route skips counting: :%normal @a runs the macro on every line of the file. Ranges work as the manual teaches: 5,12 from five to twelve, .,$ to the end, % for all.

No j is needed here; the command steps through the range line by line itself. The help's warning applies: the macro must end with a complete command, or Vim waits for the rest on every line.

Counts for a screenful, :normal for the whole file.

RECORD IT THIS WEEK

Record a macro without j and run it over a whole file with :%normal @a, then again on a 5,12 range.

Per Vim user manual, usr_10.txt: an uppercase register appends, for recording and for yank alike; this book's plan types the @ tail as text and appends it with an uppercase yank.

vim companion · No. 06
Recursive macros

Yank the @ line in

Type @b, then 0"By$

type the tail as text, yank it onto the end1qbrecord the body into b, clean, no tail2othen type two characters: @b (text, not executed)30"By$yank the line, appending it into b4dd the scratch line; @b now loops itselfan uppercase yank appends: the @ tail joins the body, no re-recording

The safe recipe, in moves. First record the body into b, clean, no tail. Then type the two characters @b on an empty line, as text, never executed.

Now the uppercase yank: from column 1, yank to the line end appending into b. The tail joins the body without re-recording; clear the scratch line and the loop is ready.

The recursion was typed as text and yanked into place: no runaway take.

RECORD IT THIS WEEK

Build one recursive macro with the four steps and run it down a twenty-line column until it stops itself at the bottom.

Per Vim help, change.txt: CTRL-A adds the count to the number after the cursor and the number formats option controls what counts as a number; this book's plan records 0, CTRL-A, j.

vim companion · No. 07
Real recording tasks

Increment the column

CTRL-A, one per line

task: number a column, one replay per linebefore, four lines1 1 1 1after 4@a1 2 3 4same key, four different resultsrecorded0 CTRL-A jCTRL-A adds one to thenumber after the cursor(change.txt)count on the keys: 0, CTRL-A, j, then a count in front of @

CTRL-A raises the number after the cursor. Record 0, CTRL-A, j: each replay goes home, bumps that line's number, steps down a line.

Four lines holding 1 become 1, 2, 3, 4 after 4@a. Same three keys, four different results: the macro supplies the plan, the buffer supplies the variety.

Numbered lists, priorities, versions: one macro, the whole column.

RECORD IT THIS WEEK

Turn a column of ten ones into one to ten with one recording and one count, then undo it all with a single u.

Per Vim user manual, usr_10.txt: :substitute replaces over a range, a visual block with I inserts one prefix across many lines, and gqap formats a paragraph.

vim companion · No. 08
Beyond one buffer

When not to macro

The dedicated tool first

reach for the dedicated tool firstsubstitute:%s/x/y/gplain replacementswant no macrovisual blockCTRL-V Ione prefix on manylines, typed onceformatgqapreformatting aparagraph is one opusr_10.txt covers all three; the macro is for the resta macro is plan B; the dedicated command is usually plan A

Three jobs that look macro-shaped and are not. Plain text swap: :s over a range. One prefix on many lines: the block insert, typed once. Reformatting: gqap, one operator.

The test: if a single command's own range or repetition covers the whole job, wrapping it in a macro is ceremony.

Reach for q when the job is a sequence of steps, not a sweep.

RECORD IT THIS WEEK

Redo one old macro task with :s or a block insert, and keep whichever take you would defend in a review.

Index

Index


:normal over a range8
Append with qA5
Increment the column10
One line per pass6
Record with q4
The macro as plan B7
When not to macro11
Yank the @ line in9