How do I paste a register in insert mode without triggering auto-indent?
Answer
<C-r><C-o>{reg}
Explanation
When you use <C-r>a in insert mode to paste register a, Vim inserts the text as if you typed it character by character. This means auto-indent, abbreviations, and mappings all fire, often mangling pasted code with unwanted indentation. <C-r><C-o>a inserts the register contents literally, bypassing all of that.
How it works
<C-r>— enters register-insert mode on the command line or in insert mode<C-o>— modifier that tells Vim to insert the text literally, without processing it as typed characters{reg}— any register name (a-z,",0,+, etc.)
The key difference is that <C-r>a simulates keystrokes (triggering 'autoindent', 'smartindent', 'cindent', abbreviations, and insert-mode mappings), while <C-r><C-o>a inserts the raw text directly.
Example
Suppose register a contains a multi-line code block and you have autoindent enabled:
# Using <C-r>a inside an indented block:
if condition:
def foo():
return bar
# extra unwanted indent on each line!
# Using <C-r><C-o>a inside an indented block:
if condition:
def foo():
return bar
# indentation preserved exactly as yanked
Tips
- This is especially valuable when pasting into already-indented code with
cindentorsmartindentactive - Also works on the command line (
:prompt) —<C-r><C-o>/pastes the search register literally - For a similar effect in normal mode, use
]pto paste with adjusted indentation or"apwithset paste