How do I append keystrokes to a macro without re-recording it?
:let @q .= 'j'
Re-recording a long macro just to add one extra keystroke is wasteful and error-prone.
:let @q .= 'j'
Re-recording a long macro just to add one extra keystroke is wasteful and error-prone.
:let @q = substitute(@q, 'foo', 'bar', 'g')
Recorded macros are plain text stored in registers, which means you can refactor them instead of re-recording from scratch.
:let @q .= 'A;<Esc>'
Re-recording a long macro just to add one extra step is slow and error-prone.
"=strftime('%Y-%m-%d %H:%M')<CR>p
The expression register lets you evaluate Vimscript on demand and paste the result immediately.
registers #registers #expression-register #automation #timestamps
@='A;<Esc>'<CR>
Recorded macros are powerful, but sometimes you need a quick ephemeral sequence and do not want to occupy a register.
:lockmarks keepjumps keeppatterns %s/\s\+$//e
Bulk cleanup commands are easy to automate, but many implementations quietly damage editor state by moving marks, polluting the jumplist, or replacing your last
:cdo normal! @a | update
When you already have a precise quickfix list, :cdo is one of the safest ways to run a macro only where it matters.
:'<,'>normal! .
When you already made one correct edit, replaying it is usually safer than retyping it by hand.
:let @q = substitute(@q, '\n$', 'A;<Esc>\n', '')
Rerecording a long macro for one tiny change is slow and error-prone.
"=strftime('%F')<CR>p
The expression register lets you compute text on demand and insert it without leaving Normal mode workflows.
registers #registers #expression-register #normal-mode #automation
:keeppatterns normal! @q<CR>
When you replay macros from Ex commands, Vim can overwrite @/ (the last search pattern) depending on what the macro does.
:echo searchcount({'recompute': 1})
Vim can show match counts for your last search, but in large files or after big edits the cached values may lag.
search #search #command-line #automation #statusline #diagnostics
:while search('TODO') | normal! @q | endwhile
A fixed count like 100@q is brittle: sometimes your macro needs 12 passes, sometimes 300, and over-running can corrupt already-processed text.
macros #macros #automation #search #normal-mode #ex-commands
:let @a .= expand('%:t') . "\n"
Named registers are not just for yanks and deletes.
:windo normal! @q
When you split a file into multiple windows or keep several related buffers visible, repeating the same small cleanup in each one can be tedious.
macros #macros #windows #normal-mode #ex-commands #automation
:echo getreg('a', 1, 1)
For advanced register debugging and macro tooling, plain getreg('a') is often not enough.
: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.
:execute "normal! gg=G"<CR>
:execute lets you build and run Ex commands dynamically, which is critical when a command depends on variables, conditionals, or string composition.
command-line #command-line #ex-commands #normal-mode #automation
:@q
Most macro workflows focus on @q, which replays register q as normal-mode keystrokes.
:'<,'>normal! A;
Visual selections are not just for direct operators; they also define an Ex range.
visual-mode #visual-mode #normal-mode #editing #ex-commands #automation