Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I got this when trying to copy this gist on vim: https://gist.github.com/w0ng/3278077

enter image description here

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?

share|improve this question

5 Answers 5

up vote 21 down vote accepted

Enter paste mode before you paste:

:set paste

To switch back to "normal" mode:

:set nopaste
share|improve this answer
    
Thanks, this worked :) –  jviotti Jul 27 '13 at 15:10
5  
or :set paste! to toggle :) –  valbaca Jul 27 '13 at 18:39
    
@valbaca You can use backticks to create code blocks in comments –  Izkata Jul 27 '13 at 18:49

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).

share|improve this answer

Here's what's happening. There are Vim formatting options that automatically comment out new lines when you are on a comment line. Some of these options are usually enabled by default. For example,

# a comment<CR>
# 

As you can see, the new line was automatically prepended with a comment character. You can disable the majority of these options by removing c and r from the setting formatoptions. See :h fo-table for more information about these options.

:set formatoptions-=cr

Vim has no way of differentiating between text that is pasted with your terminal emulator's pasting mechanisms and text that you type. Setting the paste options (set paste) tells Vim to expect pasted text and disable any formatting options that would be undesirable.

share|improve this answer

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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