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

How do I paste from a register in insert mode without triggering autoindent or mangling indentation?

Answer

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

Explanation

When you paste from a register in insert mode with <C-r>{reg}, Vim replays each character as if typed. This means autoindent rules fire on every newline and certain control characters are interpreted as commands—corrupting multi-line or heavily indented content. <C-r><C-o>{register} performs a literal insert: the register contents land verbatim in the buffer, with no indent adjustment and no special-character interpretation.

How it works

  • <C-r> initiates register insertion while in insert mode
  • <C-o> signals a raw "override" paste — the register is inserted as a single literal chunk
  • {register} is the register to read from (e.g., a, ", +, 0)

Vim defines three levels of insert-mode pasting:

Keysequence Autoindent Special chars
<C-r>{reg} applied interpreted
<C-r><C-r>{reg} applied literal
<C-r><C-o>{reg} bypassed literal

Example

Register a holds a function body with tab-indented lines:

if condition {
	do_something()
}

With autoindent on, pressing <C-r>a would add extra leading whitespace to each continued line. Pressing <C-r><C-o>a inserts the block exactly as stored — tabs and all, no extra indent added.

Tips

  • <C-r><C-o>+ pastes from the system clipboard without the autoindent interference that <C-r>+ may cause
  • <C-r><C-p>{reg} is the complementary variant: literal insert with Vim's indent-fixing applied afterward
  • All three variants are documented at :help i_CTRL-R

Next

How do I switch between character, line, and block visual selection without starting over?