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

How do I paste the contents of a register literally in command-line mode without interpreting special characters?

Answer

<C-r><C-r>

Explanation

In command-line mode, <C-r>{reg} inserts a register's contents — but it processes certain sequences, potentially misinterpreting backslashes, pipe characters, or embedded key notations. The double variant <C-r><C-r>{reg} inserts the register's raw bytes verbatim, with no interpretation at all. This distinction becomes critical when pasting complex patterns or paths that contain characters with special meaning in command-line mode.

How it works

  • <C-r>" — insert unnamed register (special chars may be processed)
  • <C-r><C-r>" — insert unnamed register literally (exact bytes, no interpretation)
  • Works with any register: <C-r><C-r>a, <C-r><C-r>/, <C-r><C-r>0, etc.
  • The raw insert is governed by :help c_CTRL-R_CTRL-R

Example

You have yanked a complex regex into register a:

\(foo\|bar\)\+

Using <C-r>a in the command line may mis-process the backslashes. Using <C-r><C-r>a inserts the pattern byte-for-byte, exactly as it was yanked, so the search or substitute works correctly.

Similarly, a file path containing a pipe:

/tmp/out|err.log

Pasted with <C-r><C-r>" keeps the | as a literal character rather than being treated as a command separator.

Tips

  • Also useful in insert mode: <C-r><C-r>{reg} pastes literally without triggering abbreviations or indent
  • <C-r><C-o>{reg} is a related variant for insert mode that additionally disables auto-indent
  • Use <C-r>" (single) when you want the normal processed paste; switch to <C-r><C-r>" when the result looks wrong
  • Check :registers to inspect register contents before deciding which form to use

Next

How do I read from and write to files directly in Vimscript without shelling out to external commands?