I will use ctrl-r quite frequently in insert mode to insert contents of a register, for example, ", %, or any of the [a-z] registers. I've also come across the following in the help:

tag             char                         action in Insert mode   
i_CTRL-R        CTRL-R {register}            insert the contents of a register
i_CTRL-R_CTRL-R CTRL-R CTRL-R {register}     insert the contents of a register literally
i_CTRL-R_CTRL-O CTRL-R CTRL- O {register}    insert the contents of a register literally and don't auto-indent
i_CTRL-R_CTRL-P CTRL-R CTRL-P {register}     insert the contents of a register literally and fix indent.

What exactly is the difference between these? For example, for the insert register literally I was thinking that it would convert something like a newline into a control-sequence, so the text:



Would be converted to something like:


But that doesn't seem to be the case. Could someone explain the differences between the four ctrl-r options perhaps using an example for how the four would actually produce a different output when pasted into vim?

  • :help i_CTRL-R_CTRL-R explains the difference and includes an example.
    – Rich
    Jun 23 '20 at 9:38
  • @Rich yes it does include an example for ab^Hc. I was more curious about some more extensive examples -- lists, dicts, strings with actual newlines and tabs in it, etc., etc.
    – David542
    Jun 23 '20 at 16:13

A good example to illustrate this is by creating a list and inserting it with CTRL-R and CTRL-R CTRL-R.

:let a=[1,2,3,4]

Now if we insert the contents of a using ctrl-r, the list will appear, with one element per line:


However, if we insert the contents of a using ctrl-r ctrl-r, we will see the list-separator (NUL) on that line:


The two other variants, CTRL-R CTRL-O and CTRL-R CTRL-P are the based on the latter, except the former will not auto-indent and the latter will.

In case a more-visual example is helpful:

enter image description here

  • Hm, i wonder if you can do the same thing with a register
    – D. Ben Knoble
    Jun 22 '20 at 21:45
  • @D.BenKnoble what do you mean by that?
    – David542
    Jun 22 '20 at 22:48
  • Well, here you used the expression register. But what about yanked text or let @a=... or a recorded macro? Just curious.
    – D. Ben Knoble
    Jun 22 '20 at 22:51
  • :help i_CTRL-R_CTRL-R suggests it matters when the register contains control characters like backspace.
    – D. Ben Knoble
    Jun 22 '20 at 22:52
  • 1
    I think this answer would benefit from an example that explains the difference between the final three versions, <C-R><C-R>, <C-R><C-O>, and <C-R><C-P>, as the Vim documentation doesn't include such an example.
    – Rich
    Jun 23 '20 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.