How do I clear the contents of a register?
Answer
:let @a = ""
Explanation
The :let @{register} = "" command empties a register. This is useful when collecting text with append operations.
How it works
:let @a = ""clears registera:let @a = "text"sets registerato specific text:let @+ = @acopies registerato the clipboard
Example
Before collecting lines with :g/TODO/y A, clear the register:
:let @a = ""
:g/TODO/y A
"ap
Tips
- You cannot clear read-only registers (
.,%,:,#) :let @/ = ""clears the search pattern (and highlighting):let @" = @0restores the default register to the last yank- Clearing before append operations prevents stale data