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

How do I insert a register's content literally in insert mode, without triggering auto-indent or mappings?

Answer

<C-r><C-r>{reg}

Explanation

When you insert a register with <C-r>{reg} in insert mode, Vim processes the content as if you had typed it — this means autoindent, autoformat, and insert-mode mappings can all fire, sometimes corrupting the text. Using <C-r><C-r>{reg} instead inserts the register content literally, bypassing all of that processing.

How it works

  • <C-r> — opens register insertion in insert mode ("typed" insertion)
  • <C-r><C-r> — opens register insertion in insert mode ("literal" insertion)
  • {reg} — the register to insert: any named register (az), 09, ", /, +, *, etc.

The difference is subtle but critical when a register contains leading whitespace, tab characters, or characters that trigger mappings. With <C-r>, Vim runs the content through the normal insert-mode processing pipeline. With <C-r><C-r>, it skips that pipeline entirely.

Example

Imagine register a holds a multi-line snippet with mixed indentation:

if condition:
	# do something

With autoindent on and expandtab set:

  • <C-r>a — Vim re-applies indentation, converting tabs and possibly adding/removing spaces
  • <C-r><C-r>a — Vim inserts the exact bytes from the register, tabs and all

Tips

  • There is also <C-r><C-o>{reg} ("insert register, not auto-indented") — similar to <C-r><C-r> but specifically suppresses auto-indent while still processing other insert-mode features
  • All three forms work in command-line mode too: <C-r><C-r>{reg} on the : or / prompt inserts the register literally
  • This matters most when pasting code into a file with textwidth, formatoptions, or aggressive indent plugins active

Next

How do I insert the entire current line into the command line without typing it?