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

How do I paste register contents in insert mode without triggering auto-indentation?

Answer

<C-r><C-o>

Explanation

When you paste a register in insert mode with <C-r>{reg}, Vim inserts the text as if you had typed it — which means auto-indent, abbreviation expansion, and other insert-mode side effects can mangle the result. Using <C-r><C-o>{reg} instead inserts the register contents literally, bypassing all of those transformations.

How it works

  • <C-r> in insert mode opens register insertion
  • Adding <C-o> before the register name switches to "literal" mode: the text is put into the buffer as-is, without character-by-character processing
  • This prevents autoindent from adding extra leading whitespace to each pasted line
  • It also prevents abbreviation expansion and similar transformations from firing

Example

Suppose register a contains a multi-line snippet:

  if condition:
      do_something()

With <C-r>a and autoindent enabled, pasting from a column-2 position doubles up indentation:

  if condition:
        do_something()

With <C-r><C-o>a, the text is inserted verbatim:

  if condition:
      do_something()

Tips

  • There is also <C-r><C-p>{reg} which inserts literally and additionally fixes indentation to match the current context — useful when you want the pasted block to conform to the surrounding file's indent style
  • For pasting from the clipboard register use <C-r><C-o>+ or <C-r><C-o>*
  • In normal mode, p and P are already literal; this technique only matters in insert mode

Next

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?