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

How do I insert a register in Insert mode without reindenting each inserted line?

Answer

<C-r><C-o>a

Explanation

When you paste multiline snippets from a register while in Insert mode, default insertion can trigger indentation and formatting side effects line by line. That is often undesirable for preformatted text, logs, or code you want to preserve exactly. The CTRL-R CTRL-O form inserts from a register in a more literal way and avoids those autoindent surprises.

How it works

<C-r><C-o>a
  • <C-r> starts register insertion from Insert mode
  • <C-o> switches to the variant that inserts the register more literally
  • a is the register name (a in this example)

Compared with plain <C-r>a, this is safer when the current buffer has aggressive indent settings or format options.

Example

Suppose register a contains:

if ready:
print("raw")

At an insert position in an indented block, using <C-r>a may reindent or reshape the pasted lines depending on local settings. Using:

<C-r><C-o>a

keeps the register text closer to its original form.

Tips

  • Use <C-r><C-p>{reg} when you want Vim to adjust indent to the current context
  • This works for numbered registers and named registers alike

Next

How do I lazy-load cfilter from vimrc without interrupting startup when it is unavailable?