VIM commenting out what I paste
Solution 1
Enter paste mode before you paste:
:set paste
To switch back to "normal" mode:
:set nopaste
Solution 2
Beside the paste
option mentioned by Mat, you can also directly access the X clipboard from VIM:
-
"*p
to insert the X11 selection -
"+p
to insert the X11 clipboard
You need a VIM version with X11 support (in Debian and its derivatives you need to install the vim-gtk
or vim-gnome
package).
For more information, see the documentation (:help x11-selection
).
Solution 3
My favorite is using the put
command.
-
:put*
paste from selection at the current line -
:put+
paste from buffer at the current line
"*p
/"+p
is also good, but :pu[t]
has some advantages:
- it always pastes linewise
- you can add an additional parameter to control where to insert:
-
:$put+
paste after the last line -
:0put+
paste at the beginning of the file
-
Solution 4
As a side answer, If you have any files which have this in you can get rid of it by entering Vertical Visual block mode
ctrl+v and then using arrow keys / hjkl to navigate the parts you wish to delete and then just hitting d
Sometimes i find this quicker than undo'ing setting paste mode, pasting and unsetting paste mode.
Comments
-
jviotti over 1 year
I got this when trying to copy this gist on vim: https://gist.github.com/w0ng/3278077
I notice the same behaviour everywhere: If I paste something that includes a comment, everything that follows the comment is pasted commented.
Maybe it has something to do with the fact that if I write a comment on insert mode and press enter, the following line automatically appends a comment.
How can I get rid of this behaviour?
-
valbaca over 10 yearsor :set paste! to toggle :)
-
Izkata over 10 years@valbaca You can use backticks to create
code blocks
in comments -
vinnydiehl over 6 yearsI needed those commands the opposite way around!
-
aegatlin about 3 yearsIs there a downside to permanently disabling past mode?