How do I insert the unnamed register literally in Insert mode without auto-indent side effects?
Answer
<C-r><C-r>"
Explanation
In Insert mode, plain <C-r>{register} inserts register content but may reindent or auto-format depending on context. <C-r><C-r>{register} inserts the same text literally, which is safer when you need exact whitespace, punctuation, or code snippets preserved. This is a strong trick for advanced editing in indentation-sensitive files.
How it works
- First
<C-r>enters Insert-mode register paste - Second
<C-r>switches to literal insertion mode "selects the unnamed register
Literal insertion bypasses formatting side effects that can happen with normal Insert-mode register paste.
Example
Assume the unnamed register contains this exact text (including leading spaces):
if (ready) {
run_job();
}
At an indented cursor position, use:
<C-r><C-r>"
Vim inserts the block as-is, preserving spacing instead of reflowing indentation.
Tips
- Use
<C-r><C-r>0to insert the yank register literally - Use
<C-r><C-r>afor a named register you keep snippets in - If you do want Vim to adapt indentation to surrounding code, use the single-
<C-r>form instead