How do I paste from a register in insert mode without Vim interpreting special characters?
Answer
<C-r><C-r>{register}
Explanation
In insert mode, <C-r>{reg} pastes from a register but treats certain bytes as key inputs — so a register containing \n triggers a newline, \x08 triggers backspace, and so on. This causes surprising edits when pasting content with embedded control characters or multi-line text.
Using <C-r><C-r>{reg} (double Ctrl-R) inserts the register's content literally — every byte is inserted as a character, with no interpretation. It is the insert-mode equivalent of :put without the newline semantics.
How it works
<C-r>{reg}— paste register; special bytes are acted on (can trigger commands or modify the buffer unexpectedly)<C-r><C-r>{reg}— paste register literally; all bytes inserted as-is
A third variant, <C-r><C-o>{reg}, pastes literally and does not auto-indent — useful when autoindent or smartindent would mangle the pasted block.
Example
Suppose register a contains foo\nbar (a literal newline in the middle). In insert mode:
<C-r>a → inserts two lines (newline is interpreted as Enter)
<C-r><C-r>a → inserts the literal string including the newline char, staying on one line
This matters when building search patterns, command arguments, or string literals where control characters must be verbatim.
Tips
- Use
<C-r><C-o>"to paste the unnamed register literally without auto-indent — ideal for code blocks in files withautoindenton - The same
<C-r><C-r>trick works in command-line mode (:) to paste register content into an Ex command literally - Check a register's raw content with
:reg {name}before pasting to see if it contains control characters