How do I save the current search pattern into a named register before it gets overwritten by a new search?
:let @a = @/
Vim stores the last search pattern in the special / register (@/).
351 results for "registers"
:let @a = @/
Vim stores the last search pattern in the special / register (@/).
:let @q = 'commands'
Macros in Vim are just text stored in named registers.
vim.highlight.on_yank()
After yanking text in Vim it can be hard to tell exactly what was captured, especially with larger motions or text objects.
: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
[p
When you copy code from one indentation level and paste it at another, p preserves the original indentation, leaving your code misaligned.
"#p
The # register holds the name of the alternate file — the file you were editing just before the current one.
:let @/ = '\V' . escape(expand('<cword>'), '\')
This pattern lets you prepare a precise search target without jumping the cursor or triggering an immediate search motion.
Record worker macro in @b, call it from @a with @b
Complex macros are hard to debug and maintain when crammed into a single register.
yiw{nav}viwp{nav}viwp
When you paste over a visual selection in Vim, the displaced text is moved into the unnamed register "".
registers #registers #visual-mode #editing #text-objects #normal-mode
:put a ... edit ... "ayy
Recorded macros are stored as plain text in registers, but editing them by re-recording is tedious for complex sequences.
systemlist()
systemlist({cmd}) runs a shell command and returns the output as a list of strings, one per line — unlike system() which returns everything as a single string
:let @q = substitute(@q, 'from', 'to', 'g')
Macros are stored as plain text in named registers, so you can manipulate them with any Vimscript string function.
When recording a macro, you can execute another macro inside it by pressing @b (or any register) during the recording.
:s/\d\+/\=submatch(0)+1/g
The \= prefix in a :substitute replacement field tells Vim to evaluate the following as a Vimscript expression rather than treating it as a literal string.
: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.
<C-r>=expression<CR>
The expression register ("=) evaluates Vimscript expressions and returns the result.
registers #registers #insert-mode #expression #calculator #vimscript
:let @q .= "keys"
The string concatenation assignment :let @q .
@"
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
qaq
How it works To clear a macro register, you simply start recording into that register and immediately stop.
:let @a = execute('messages')
The execute() function (added in Vim 8.