How do I append new keystrokes to an existing macro register without re-recording it?
:let @q .= 'A;<Esc>'
Re-recording a long macro just to add one extra step is slow and error-prone.
272 results for ":q!"
:let @q .= 'A;<Esc>'
Re-recording a long macro just to add one extra step is slow and error-prone.
:echo string(getreg('q'))
Macros can fail for subtle reasons: hidden control keys, extra whitespace, or unexpected register contents.
registers #registers #macros #debugging #automation #command-line
:put =strtrans(@q)<CR>
Macro failures are often caused by hidden control keys like , , or tabs that are hard to see in raw register output.
:let @q =
Instead of recording a macro with q, you can assign any string directly to a named register using :let @{register} = 'keys'.
:let @q .= "A;\<Esc>"
If a recorded macro is almost correct but missing a final step, re-recording from scratch is slow and error-prone.
@q (inside macro recording)
A recursive macro calls itself as its last action, causing it to repeat indefinitely until it hits an error (like reaching end of file or failing a search).
:let @q = "dd"
Macros are just strings stored in named registers.
:for i in range(1,10) | execute "normal @q" | endfor
Using a Vimscript :for loop with execute "normal @q" lets you run a macro with a dynamically computed iteration count and interleave other Ex commands between i
:let @q = @:
The : register always holds the last Ex command you ran.
:[range]normal @q
The :[range]normal @q command replays the macro in register q on every line within a given range.
qa f,ldt,F(p q
This macro swaps two comma-separated arguments inside parentheses by cutting the second argument and placing it before the first.
let @q = 'keystrokes'
Macros recorded with q{register} are stored in registers and lost when Vim exits.
qa ... j@bj q
You can create macros that call other macros, applying different operations to alternate lines or creating complex editing patterns.
:let @q = '{keystrokes}'
You can assign a string directly to any register using :let @{reg} = '.
qqgUiwjq2@q
Macros are strongest when the edit pattern is stable but too awkward for a one-liner substitute.
5@q
Prefix the @ macro-execution command with a count to run the macro that many times in a row.
:let @q .= "j^"
Live macro recording is fast, but adjusting the tail of a macro by re-recording can be risky once it already works in most places.
macros #macros #registers #automation #normal-mode #workflow
q?
Vim provides three command-line history windows accessible from normal mode: q: for Ex commands, q/ for forward searches, and q? for backward searches.
q/k?pattern<CR>
Vim's command-line history window (q: for Ex commands, q/ for search) opens a full editing buffer containing your history.
]q
The vim-unimpaired plugin (by Tim Pope) provides a consistent [x / ]x mnemonic for navigating any list-like structure in Vim.