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
autoindentfrom 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,
pandPare already literal; this technique only matters in insert mode