Vim Tip: using “paste” to avoid the staircase effect

If you’re working in Vim and paste something into the terminal, sometimes you’ll get a “staircase” effect where each line is progressively spaced farther outward, like so:

line 1
 line 2
  line 3
   line 4

Obviously, this isn’t usually desirable.

To correct this, you can enable paste to prevent the staircase effect. In command mode, type:

:set paste

This isn’t on by default. When paste is enabled, it disables mapping and some other functions, so you probably want to know how to turn it off as well:

:set nopaste

Happy vimming!

About Joe Brockmeier

I'm a freelance writer, FOSS advocate, music lover, computer geek, avid reader, and politically progressive (read "Liberal with occasional Libertarian tendencies"). You can read more on my about page if you're not already bored.
This entry was posted in Linux, Linux.com, Open Source, Vim, openSUSE and tagged , . Bookmark the permalink.

16 Responses to Vim Tip: using “paste” to avoid the staircase effect

  1. ptr_uzl says:

    Cool, thanks for the tip!

  2. Rajeesh says:

    Thanks a lot for the tip!
    I was nagged by this more occasions than once.

  3. KimTjik says:

    Thanks! As a fairly new user of Vim I’ve been looking for a solution to this. I don’t know why but if Vim is started directly I don’t get the stair-effect, but when called from Mutt I get it. “:set paste” works perfectly. Vim is so complex it sometimes takes a lot of time to even find straight forward info about basics.

  4. lefty.crupps says:

    I’ve always used
    :set noai
    to set ‘no auto-indent’. Seems to have the same effect though.

  5. mark says:

    Can vim auto-justify text without cutting words? The only tool I know of that does that well is pico (now called ‘nano’) editor. To do that in nano you size the window just a bit bigger than you want the text to be and press Ctrl+J

    If I could do that in vim that would be great, what I do now is save the file in vim, exit vim and use nano to do the justify.

  6. Chris Jones says:

    I have the following key binding:

    set pastetoggle=

    in my ~/.vimrc so I can just poke F9, paste something and poke F9 again to go back to normal.

  7. Lou says:

    I usually get that problem with ai, but I never imagine that paste/nopaste would have the same effect. I need ai while writing code and I rather leave it on if set paste does the trick.

  8. pdwalker says:

    Did you consider turning off autoindent which is what causes the staircase effect?

    :set noai

  9. Adren says:

    the difference with noai (no autoindent) is that paste goes a bit further:
    it paste the buffer “as is” regardless of any end of line return
    i.e.: let’s say you have a tw=72 (typing a text with formatting lines of 72 characters), then the nopaste has better effect on copied text than noai.

  10. overbey says:

    Like lefty.crupps, I have always done a :set noauto or :set no auto indent, depending on OS and weather vi or vim was used. But will try the set paste

  11. bitslinger says:

    I was not aware of the paste parameter. I would use “set noautoindent” instead. I’ll have to try the paste command the next time I need to eliminate stairstepping.

    Thanks

  12. Kees Schoenmakers says:

    Hurray, now my next question:

    how to set vim so that the arrow keys allow for navigation within the text and not inserting lines with a capital D in it?

    keess2 at schoen dot mine dot nu

  13. libdave says:

    I usually do

    :r!cat

    then paste and end with ^D

  14. Avin says:

    Thanks for the cool tip…

  15. chethan says:

    Thanks for a nice tip. I often face this problem.

  16. I use the ‘set paste’ option as well as some other neat tricks (status line in vim).

    Take a look at some of the handy options I employ here:

    http://ddhj.homeip.net/wiki/doku.php/profile_tricks_examples#vim

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>