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 registerd{motion},dd,c{motion},xall 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 :regshows 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