How do I execute Ex commands stored in a register instead of replaying it as normal-mode keys?
:@q
Most macro workflows focus on @q, which replays register q as normal-mode keystrokes.
:@q
Most macro workflows focus on @q, which replays register q as normal-mode keystrokes.
:keepjumps normal! 500@q
Running a macro hundreds of times is efficient, but it can flood your jumplist and make normal navigation painful afterward.
qqgUiwjq2@q
Macros are strongest when the edit pattern is stable but too awkward for a one-liner substitute.
:'a,'bnormal! @q<CR>
When you need to replay a macro on a precise region, selecting lines manually can be slow and error-prone.
:'<,'>normal @@
When you already have a useful macro but need to apply it to a specific block of lines, :'normal @@ is a high-leverage pattern.
:cdo normal! @q
When a refactor target spans many files but only specific matches matter, running a macro globally is risky.
: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
: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
:wn
:wn (short for :wnext) writes the current buffer to disk and immediately advances to the next file in the argument list.
let {var} =<< {marker}
Vim 8.
:try / :catch / :endtry
Vimscript has a structured exception handling system using :try, :catch, :finally, and :endtry.
:args **/*.py | argdo %s/old/new/ge | update
Combining :args, :argdo, and :update gives you a powerful in-editor multi-file search and replace without leaving Vim.
vim.keymap.set('n', '{key}', {fn}, { desc = '{description}' })
When defining keymaps with vim.
:reg {names}
The :registers command dumps every register at once, which is noisy when you only care about a handful.
mode()
The mode() function returns a short string identifying the current editing mode — 'n' for Normal, 'i' for Insert, 'v' for Visual character-wise, 'V' for Visua
macros #macros #normal-mode #visual-mode #insert-mode #editing
input({prompt})
The built-in input() function pauses execution, displays a prompt at the bottom of the screen, and returns whatever the user types before pressing Enter.
:let @q .= "keys"
The string concatenation assignment :let @q .
"qp {edit} 0"qy$ dd
When you record a macro and realize it has a mistake, the easiest fix is to paste the macro's keystrokes as text, edit them, and yank the corrected version back
Q
In Neovim, the Q key is mapped to replay the last executed macro — the same as @@ in both Vim and Neovim.
:reg {name}
The :reg {name} command displays the current contents of one or more named registers in a formatted listing.