vimtricks.wiki Concise Vim tricks, one at a time.

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 register a
  • :let @a = "text" sets register a to specific text
  • :let @+ = @a copies register a to 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 @" = @0 restores the default register to the last yank
  • Clearing before append operations prevents stale data

Next

How do you yank a single word into a named register?