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

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 name
  • 0 is 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 by d, c, s, and x
  • <C-r>0 is immune to this: only an explicit y overwrites register 0

Example

Original word:  myFunction
Target line:    callSomething(___)
  1. Yank myFunction with yiw
  2. Navigate to the insertion point inside the parentheses and enter Insert mode (i)
  3. Delete the placeholder if needed (<C-w>)
  4. Press <C-r>0 — inserts myFunction even if you deleted text along the way

Tips

  • <C-r><C-o>0 pastes literally (without any auto-indent or line-break adjustment), useful for multi-line yanks
  • Use :reg 0 to 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 of p) to paste from the yank register

Next

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