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

How do I delete text without overwriting my current yank register?

Answer

"_d{motion}

Explanation

The black hole register "_ discards anything written to it — it accepts input but produces no output. When you prefix a delete command with "_, the deleted text disappears silently without touching the unnamed register "" or the numbered registers "1"9. Your previously yanked text stays ready for pasting.

The problem it solves

Vim's normal d (delete) command stores the deleted text in the unnamed register, overwriting your last yank. This is the common frustration when you yank a word, position your cursor, delete the target word, then p — only to paste back the text you just deleted instead of what you yanked.

Solution:

yiw          " yank the word you want to paste
...
"_diw        " delete the target word — unnamed register untouched
p            " paste the originally yanked word

Usage

  • "_dd — delete a line without saving it to any register
  • "_dw — delete a word silently
  • "_d$ — delete to end of line, discarding the text
  • "_c{motion} — change text without clobbering the yank register
  • "_x — delete a single character silently

Tips

  • The yank register "0 always holds the last yanked (not deleted) text, making "0p a reliable alternative to using "_ for delete-then-paste workflows
  • "_ also works with s, c, and x operators — any command that would normally write to the register
  • Map a convenient shortcut for frequent use: nnoremap <leader>d "_d
  • :help registers explains all register types including the black hole register

Next

How do I run a search and replace only within a visually selected region?