How do I clear or reset a specific register in Vim?
Answer
:let @a = ''
Explanation
Registers persist their contents throughout your Vim session and even across sessions if viminfo or shada is enabled. You can explicitly clear individual registers using :let, which is useful when registers contain sensitive data or stale content you no longer need.
How it works
:let @a = ''— clears registeraby setting it to an empty string:let @a = 'new content'— replaces register content entirely:let @" = ''— clears the unnamed (default) register:let @+ = ''— clears the system clipboard register
Example
" Clear a named register
:let @a = ''
" Clear all lowercase registers with a loop
:for i in range(char2nr('a'), char2nr('z')) | call setreg(nr2char(i), '') | endfor
" Clear the search register (removes highlighting)
:let @/ = ''
Tips
- Clearing
@/removes search highlighting without:nohlsearch - Use
setreg('a', '', 'c')to also reset the register type to characterwise - Registers
a-zpersist inviminfo/shada— clearing them prevents leaking sensitive data - The black hole register
"_doesn't need clearing — it always discards