Search code examples
vim

How to stop vim from inserting comment characters while pasting from the clipboard?


When I paste lines, like the ones below, to Vim,

" OmniCppComplete
let OmniCpp_NamespaceSearch = 1

Vim automagically adds the " comment character to all lines. How do I get rid of this and have it paste as it is?

What I'm getting after the paste in Vim:

 66     " OmniCppComplete
 67     " let OmniCpp_NamespaceSearch = 1

Solution

  • Two main options:

    • Put directly from the register without ever entering insert mode, using  "+p
      • " means "use the following register";
      • + refers to the clipboard, and
      • p for put!

    Should you be using the middle click selection paste in Linux, use * instead of + to refer to it.

    • Before entering insert mode to paste, run :set paste. Turn it off once you leave insert mode with :set nopaste.