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

How do I paste the contents of a register into the command line or search prompt?

Answer

<C-r>"

Explanation

Pressing <C-r> followed by a register name while on the : command line or / search prompt pastes that register's contents directly into the command line. This lets you reuse yanked text, filenames, or search patterns without retyping them.

How it works

  • <C-r> triggers register-paste mode on the command line
  • The next key you press is the register name
  • Common registers to use:
    • " — unnamed register (last yanked or deleted text)
    • 0 — yank register (text from the last y command)
    • + — system clipboard
    • / — last search pattern
    • % — current file name
    • az — any named register

Example

You yanked a word with yiw. Now you want to substitute it:

Cursor on word: foobar

On the command line, type :%s/ then press <C-r>" to insert foobar, then continue:

:%s/foobar/newword/g

Or in search mode — press /, then <C-r>0 to paste the last yanked text as your search term.

Tips

  • <C-r><C-w> inserts the word under the cursor directly into the command line — useful for :grep or :substitute without yanking first
  • <C-r><C-a> inserts the WORD (space-delimited) under the cursor
  • Works in both command-line mode (:) and search mode (/ and ?)
  • In insert mode, <C-r> works the same way to paste registers without leaving insert mode

Next

How do I rename a variable across all case variants (snake_case, camelCase, MixedCase) at once?