1

Suppose I copy some code from a place and try to paste it into Vim, it comes as a comment. Is there any way to fix this?

Example:

--Return the smaller  thing

p ::forall a. (Eq a)=> [a]-> a->a->a

p z a b | rank z a >= rank z b =b
        | otherwise = a

--Return the bigger thing

g ::forall a. (Eq a)=> [a]-> a->a->a

g z a b | rank z a <= rank z b =b
        | otherwise = a

I copy the above code block into Vim and I get :

enter image description here

2
  • 2
    Welcome to Vi an Vim SE. Please post code as text, not as an image.
    – Friedrich
    Feb 29 at 19:27
  • Do you still have something open in your question? How can we help you further? Otherwise maybe could you accept one of the answers using the v button next to the arrow voting buttons? It allow the question to rest :-) Mar 3 at 15:01

2 Answers 2

1

Try :set paste before you paste (and make sure to :set nopaste afterward). If your terminal can communicate via bracketed paste that the insertion comes from a paste, Vim will essentially do this automatically.

The issue comes from seeing the first comment line and trying to extend the comment line when a new line is started; the paste option disables this treatment, among others.

You can also paste from the * or + registers to interact with the clipboard or selection.

1
  • There’s also useful support for paste-based operations in the unimpaired plugin from tpope
    – D. Ben Knoble
    Mar 1 at 3:19
0

When you paste in insert mode by default (if the paste option is unset) the clipboard is inserted like it would have been typed by the user. In particular if you paste in a comment Vim will consider the clipboard as a comment continuation.

To avoid that I recommend to past in Normal mode using either:

  • p or
  • ]p

Where ]p paste the content of the clipboard respecting the current indentation.

More information with :help ]p

1
  • 1
    I think you meant “if the paste option is _un_set.”
    – D. Ben Knoble
    Mar 1 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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