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

How do I paste a register's contents in insert mode without triggering autoindent or other text processing?

Answer

<C-r><C-r>{register}

Explanation

In insert mode, <C-r>{register} pastes the register's contents but runs it through Vim's insert-mode processing — including autoindent, textwidth wrapping, and formatoptions. For multi-line text or code with indentation, this can silently corrupt the pasted content. <C-r><C-r>{register} inserts the register's text literally, bypassing all insert-mode text processing.

How it works

  • <C-r>{register} — pastes register content, subject to autoindent, formatoptions, and textwidth reformatting
  • <C-r><C-r>{register} — pastes literally: no autoindent adjustment, no line-wrapping, no special character interpretation
  • The extra <C-r> acts as a "raw" modifier for the following register reference

A third variant, <C-r><C-o>{register}, pastes literally and also does not move the cursor to the end of the pasted text (useful when inserting inline).

Example

Suppose register a contains a multi-line Python block with intentional indentation:

for i in range(10):
    print(i)

With autoindent on, <C-r>a may double-indent the second line. <C-r><C-r>a pastes both lines exactly as stored.

Tips

  • Use <C-r><C-r>" to paste the unnamed register literally — handy when working on indented code
  • This technique is especially important when pasting code captured via :redir or system() into a buffer
  • In command-line mode, <C-r><C-r>{register} also works to paste literally without escaping special characters

Next

How do I use a Vimscript expression to compute the replacement text in a substitution?