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

How do I delete or change text without overwriting my previously yanked text?

Answer

"_d{motion}

Explanation

Vim's black hole register ("_) acts as a write-only sink: anything sent to it is discarded without affecting any other register, including the unnamed register ("). This solves one of the most common frustrations for Vim users — losing a carefully yanked value when deleting unrelated text before pasting.

How it works

  • "_ prefixes an operation with the black hole register
  • d{motion}, dd, c{motion}, x all write to the unnamed register by default
  • Prefixing with "_ discards the text instead
  • Your previously yanked text stays safely in the " (unnamed) register

Example

Suppose you yank a value to paste elsewhere:

old_function_name

Then you need to delete a word before pasting, but a plain dw would overwrite your yank. Instead:

yiw          " yank 'old_function_name'
/target<CR>  " jump to the word to delete
"_dw         " delete word → black hole (yank preserved)
p            " paste 'old_function_name'

Tips

  • Works with any operator: "_dd (delete line), "_cw (change word), "_x (delete char)
  • Use "_c{motion} when you want to replace text without putting the old content in the register
  • :reg shows all registers — "_ will never appear there since it never stores anything
  • The small-delete register ("-) is different: it holds single-character and sub-line deletes

Next

How do I define autocmds safely so they don't duplicate when my vimrc is re-sourced?