Vim Paste Indentation Messed Up (Staircase Effect)

Workaround available Linux, macOS, WSL Updated October 21, 2026

Quick answer

Autoindent re-indents each pasted line. Use :set paste before pasting (and :set nopaste after), or paste from the clipboard register with "+p.

Most likely fix: Toggle paste mode.

Symptoms

Code pasted from the browser into Vim drifts further right on every line, comments get repeated, or mappings fire during the paste.

Why it happens

  • Terminal sends pasted text as typed keys, so autoindent/smartindent apply
  • Terminal or tmux doesn't support bracketed paste
  • Older Vim builds without the bracketed-paste fix

How to fix it

Try these in order — the most common fix is first.

  1. 1. Toggle paste mode

    1. :set paste
    2. Enter Insert mode and paste
    3. :set nopaste afterwards (paste mode also disables mappings)
  2. 2. Map a toggle key

    1. Add set pastetoggle=<F2> to ~/.vimrc
    2. Press F2 before and after pasting
  3. 3. Paste from the register instead

    1. In Normal mode use "+p (needs +clipboard)
    2. In Insert mode use Ctrl-R Ctrl-P + to insert without re-indenting
  4. 4. Use a terminal with bracketed paste

    1. Modern Vim detects bracketed paste and disables autoindent while pasting
    2. Make sure tmux and your terminal emulator are up to date

This guide also covers

  • vim paste indentation
  • vim paste staircase
  • vim set paste
  • vim paste messes up formatting

Still not working?

If Vim keeps failing, you're not alone. See every Vim problem users report or the alternatives people switch to.

Other Vim errors