Macros
This post extracts some knowledge from Practical Vim Chapter 11 -- Macros.
[!TIP] Record and Execute a Macro
The q key functions both as the “record” button and the “stop” button. To begin recording our keystrokes, we type q{register}, giving the address of the register where we want to save the macros.
The @{register} command executes the contents of the specified register. We can also use @@, which repeats the macro that was invoked most recently.
[!TIP] Normalize, Strike, Abort
The golden rule is this: when recording a macro, ensure that every command is repeatable.
[!TIP] Play Back with a Count
22 is a good number.
[!TIP] Repeat a Change on Contiguous Lines
~ toggle character case.
[!TIP] Append Commands to a Macro
qA qB to append commands to the end of Macro.
[!TIP] Act Upon a Collection of Files
:argdo normal @a
Execute the marco in all of the buffers in the argument list.
[!TIP] Evaluate an Iterator to Number Items in a List
:let i = 1
qa
I<C-r>=i<CR>)
<Esc>
:let i += 1
q
[!TIP] Edit the Contents of a Macro
We can edit the macro as plain text by pasting it into the document and back to the register.

浙公网安备 33010602011771号