How do I always access my last yanked text regardless of deletes?
Answer
"0p
Explanation
Register 0 (the yank register) always contains the text from your most recent yank command — and unlike the unnamed register, it is never overwritten by deletes. This solves the classic problem of yanking text, deleting something, and losing your yank.
The problem
yiw " Yank a word — goes to both "" and "0
dd " Delete a line — overwrites "" but NOT "0
p " Pastes the deleted line (from ""), not the yanked word!
The solution
yiw " Yank a word
dd " Delete a line
"0p " Paste from register 0 — always the last YANK
Register behavior summary
| Register | Contains | Updated by |
|---|---|---|
"" (unnamed) |
Last yank OR delete | Both y and d/c/x/s |
"0 (yank) |
Last yank ONLY | Only y commands |
"1-"9 |
Delete history | Only d/c commands |
"- (small delete) |
Last small delete (<1 line) | Small d/c/x |
Common workflow
- Yank the text you want to paste:
yiw - Navigate to target, delete what's there:
diw - Paste your yank:
"0p
Tips
"0works in insert mode too:<C-r>0pastes the last yank- Many Vim users map
pin visual mode to use"0by default:vnoremap p "0p - Check
:reg 0to see what's in the yank register - Understanding registers
"","0, and"1-"9is crucial for mastering Vim's clipboard system