How do you paste with vim without code being commented?

Vim

Vim Problem Overview


Everytime I paste in vim, every line is commented out.

Is there a way around this?

Vim Solutions


Solution 1 - Vim

Before you paste, type this in normal mode:

:set paste

Then enter insert mode. You will see the status bar say insert (paste). Paste your code. Hit ESC to return to normal mode, and:

:set nopaste

You are no longer in paste mode.

Solution 2 - Vim

Or, to avoid having to turn paste on and off, just put the text. Rather than going into insert mode and pasting, in command mode type:

"+p

The + buffer corresponds to the system clipboard.

If you insist on using paste, I'd suggest mapping something to toggle it. For example, :set pastetoggle=<F2> (wow, didn't realize there was a special option for that)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTripView Question on Stackoverflow
Solution 1 - VimpkaedingView Answer on Stackoverflow
Solution 2 - VimCascabelView Answer on Stackoverflow