Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim inserting comments while copy pasting

Tags:

vim

People also ask

How do I paste properly in Vim?

That makes the default paste buffer map to X's clipboard. So, if I mark a bit of text in a terminal, I can simply press p to paste it in vim. Similarly, I can yank things in vim (e.g. YY to yank the current line into the buffer) and middle click in any window to paste it.

How do I copy and paste text in Vim?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do you paste a yanked line?

To yank one line, position the cursor anywhere on the line and type yy . Now move the cursor to the line above where you want the yanked line to be put (copied), and type p . A copy of the yanked line will appear in a new line below the cursor. To place the yanked line in a new line above the cursor, type P .


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.

In Vim go to the mode :set paste. Then press Ctrl + Shift + V.

It would work.

Don't paste by going to edit and paste. It won't work.


Everybody so far is missing the point. Vim is automatically inserting the comment field when you start a new line (whether it is from a paste or from your typing).

You have formatoptions set with at least the r and maybe the o option. To see your settings, type

:set formatoptions?

To remove those options, type

:set formatoptions=

Paste will then work the way you expect.

Type

:help fo-table

to see what the letters in formatoptions each mean.