Skip to content

Pasting in Vim

When you want to paste in Vim, you want vim to not use indenting, because that messes up your code. I used to use :insert, but on some machines, it would still indent. I discovered the :set paste command, which works quite well.

3 Comments ( Add comment / trackback )

  1. (permalink)
    Comment by Rowan Rodrik
    On January 13, 2010 at 23:41

    I often use the following if :insert doesn’t give me the desired result:


    I learned that trick from Kim Hendrikse a long time ago. It also works in ol’ vi.

  2. (permalink)
    Comment by Rowan Rodrik
    On January 31, 2010 at 23:57

    While researching another post, I actually just used :set paste for the first time and was amazed by how well it works. I recommend anyone to try it. I especially like how every subsequent time that you change to insert mode, it will have this (clearly) enabled until it’s explicitly disabled again.

    However, in that same post that I was working on, I also introduce the following solution, which uses the excellent XSel tool to do the same, with more flexibility and power (I think). Here’s an example with xsel that pastes the contents of PRIMARY:


    Or, if you prefer the CLIPBOARD:

    :r!xsel -b

    That’s how easy it is.

  3. (permalink)
    Comment by halfgaar
    On February 2, 2010 at 00:10

    Hmm, my vim only has insert mode enabled once. If you go to command mode and then back to insert, it’s no longer paste mode. And that’s the way I prefer it.