How do I paste the last yanked text while in Insert mode without using the unnamed register?
Answer
<C-r>0
Explanation
In Insert mode, <C-r>{reg} pastes the contents of any register inline at the cursor. Using register 0 specifically ensures you paste the last yanked text — not text that was deleted or changed, which overwrites the unnamed register ". This is essential when you yank something and then make edits before pasting.
How it works
<C-r>in Insert mode opens a prompt to type a register name0is Vim's yank register: it always holds the most recently yanked text, regardless of any subsequent deletions<C-r>"(unnamed register) holds the last yank or delete — it gets overwritten byd,c,s, andx<C-r>0is immune to this: only an explicityoverwrites register0
Example
Original word: myFunction
Target line: callSomething(___)
- Yank
myFunctionwithyiw - Navigate to the insertion point inside the parentheses and enter Insert mode (
i) - Delete the placeholder if needed (
<C-w>) - Press
<C-r>0— insertsmyFunctioneven if you deleted text along the way
Tips
<C-r><C-o>0pastes literally (without any auto-indent or line-break adjustment), useful for multi-line yanks- Use
:reg 0to inspect the current contents of the yank register before pasting - For clipboard integration,
<C-r>+pastes from the system clipboard in Insert mode - In Normal mode, use
"0p(instead ofp) to paste from the yank register