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

How do I paste from a register in the command line?

Answer

<C-r>{reg} in command line

Explanation

While on the : command line, pressing <C-r> followed by a register name inserts that register's contents. This is essential for building commands with dynamic content.

How it works

  • <C-r>a pastes register a into the command line
  • <C-r>" pastes the default register
  • <C-r>/ pastes the last search pattern
  • <C-r><C-w> inserts the word under cursor

Example

To search and replace the word under cursor:

:%s/<C-r><C-w>/replacement/g

Tips

  • <C-r><C-a> inserts the WORD under cursor
  • <C-r><C-l> inserts the current line
  • Works in both : command line and / search prompt
  • <C-r>= evaluates an expression and inserts the result
  • Double <C-r><C-r> inserts literally without interpretation

Next

How do you yank a single word into a named register?