Smokes your problems, coughs fresh air.

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

  1. Rowan Rodrik

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

    :r!cat</dev/tty

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

  2. Rowan Rodrik

    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:

    :r!xsel
    

    Or, if you prefer the CLIPBOARD:

    :r!xsel -b
    

    That’s how easy it is.

  3. halfgaar

    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.

© 2024 BigSmoke

Theme by Anders NorenUp ↑