2026 maintenance note: The first part of this page is a current troubleshooting guide for Vim and Neovim. The final archive section preserves the complete 2019 source export verbatim, including its wording, Markdown, commands, and historical Stack Overflow link. The old
:set pasteworkflow remains a valid manual fallback in Vim, but modern Vim can recognize bracketed terminal paste, while Neovim handles paste automatically and removedpastetoggle. Those paths should no longer be presented as interchangeable.
Table of Contents
The short answer
If a terminal paste makes every line drift farther to the right, first identify the editor:
:version
:echo has('nvim')
Then use the matching path:
| Environment | What to do |
|---|---|
| Vim, one broken paste | Run :set paste, paste in Insert mode, then immediately run :set nopaste |
| Vim, repeated broken pastes | Fix bracketed paste if possible; otherwise configure set pastetoggle=<F3> as a manual fallback |
| Neovim | Do not add pastetoggle; it was removed. Normal terminal or GUI paste should be handled automatically |
| Vim or Neovim with a working clipboard register | Leave Insert mode and use "+p, avoiding terminal keystroke injection altogether |
Do not put set paste permanently in a Vim configuration. Paste mode deliberately disables or changes mappings, abbreviations, indentation, tabs, wrapping, and formatting behavior. Leaving it enabled solves one paste while quietly breaking normal editing.
Why pasted code becomes a staircase
A terminal can deliver pasted text as if the user typed every character. If the editor cannot distinguish that stream from typing, each newline can trigger autoindent, smartindent, cindent, indentexpr, comment continuation, or other formatting rules. The indentation already present in the clipboard is then added on top of newly calculated indentation, producing a staircase:
if condition:
first_call()
second_call()
third_call()
Bracketed paste solves the classification problem. A supporting terminal surrounds pasted text with start and end markers. Vim or Neovim can then insert the block as paste instead of interpreting it as ordinary typing. This depends on the entire path—terminal, SSH session, multiplexer such as tmux, and editor—preserving and understanding the protocol.
Vim: the manual paste workflow
For Vim, the 2019 procedure is still a valid fallback:
:set paste
Enter Insert mode and paste. When finished, return to Normal mode and restore normal behavior:
:set nopaste
If this is genuinely needed often, Vim’s current help still documents pastetoggle:
set pastetoggle=<F3>
Press <F3> before and after the paste. pastetoggle is different from an ordinary Insert-mode mapping because Vim ignores Insert-mode mappings while paste is active; the dedicated option remains available to turn paste mode back off.
Check the current state at any time:
:set paste?
If Vim reports paste after the paste has ended, run :set nopaste. The Vim FAQ explicitly warns against leaving the option permanently enabled.
Current Vim behavior: bracketed paste first
Current Vim documents bracketed paste under :help xterm-bracketed-paste. When the terminal protocol is available, Vim receives paste boundary markers and inserts the payload literally rather than treating it as commands. In that working path, no manual toggle is needed.
The manual switch remains useful when the terminal path is old or misconfigured, but it should be a fallback rather than the first permanent customization. Vim’s documentation also warns that bracketed paste is not a security guarantee: terminals can implement it differently, so inspect untrusted text before pasting it into an editor or command line.
Neovim: remove the old toggle
Neovim’s current provider documentation says TUI paste uses the terminal’s bracketed-paste capability and works automatically when the terminal supports it. GUIs call Neovim’s paste API. Since Neovim 0.9, pastetoggle has been removed and the paste option is obsolete.
Therefore, this old Vim setting does not belong in a current Neovim configuration:
set pastetoggle=<F3>
If it produces an unknown-option error in init.vim, remove it. If Neovim paste still reindents or inserts raw escape markers, diagnose the terminal, multiplexer, GUI, or configuration path instead of rebuilding the removed toggle.
A reproducible troubleshooting sequence
1. Confirm the editor and version
Use :version, not the shell command name or the appearance of the interface. Configuration shared between Vim and Neovim is a common source of obsolete options.
2. Isolate the configuration
Start the same editor without user configuration:
vim --clean
nvim --clean
Paste a small harmless sample. If the clean session works, inspect the normal configuration, filetype plugins, indentation plugins, and paste mappings. If the clean session fails too, the terminal, SSH, or multiplexer path becomes the stronger suspect. This comparison is evidence, not proof: repeat it inside and outside tmux or the remote session before changing terminal settings.
3. Inspect Vim’s option state and origin
In Vim, run:
:verbose set paste?
:verbose set autoindent? smartindent? cindent? indentexpr?
verbose can report the script that last changed an option. A stuck paste explains missing mappings or indentation after a paste; an unexpected indentexpr or filetype plugin may explain transformations that occur only for one file type.
4. Bypass terminal paste with a register
If the system clipboard is available to the editor, paste from the + register in Normal mode:
"+p
From Insert mode, type Ctrl-R, Ctrl-O, then +. The documented CTRL-R CTRL-O {register} form inserts a register literally without auto-indenting. This separates an editor indentation problem from a terminal paste-protocol problem.
If the + register is unavailable, that is a clipboard-provider issue, not evidence that paste mode is broken. In Neovim, run :checkhealth; its built-in checks include clipboard support. In Vim, inspect :version for clipboard features and use the clipboard method supported by that build and operating system.
5. Test the transport path
If the buffer contains literal text such as ^[[200~, a bracketed-paste marker reached the buffer without being recognized. If behavior differs outside tmux, outside SSH, or in another terminal, compare those layers before changing Vim indentation options. Avoid copying arbitrary terminal escape-code snippets into a configuration: current Vim can use terminfo support, and a manual value that is wrong for one terminal can create a second problem.
Symptom-to-cause table
| Symptom | Likely boundary to inspect | First check |
|---|---|---|
| Every pasted line shifts farther right | Paste is being interpreted as typed input | Try a clean session, then Vim’s temporary :set paste |
| Mappings, abbreviations, or normal indentation stop working after a paste | Vim was left in paste mode | :set paste?, then :set nopaste |
Neovim reports that pastetoggle is unknown |
A Vim-only legacy setting is in Neovim config | Remove it; use automatic paste and test nvim --clean |
Literal ^[[200~ or ^[[201~ appears |
Bracketed-paste markers were not handled across the terminal path | Compare outside tmux/SSH and in another terminal |
"+p fails or the + register is empty |
Clipboard support/provider is unavailable | Neovim :checkhealth; Vim :version |
| Only one file type is affected | A filetype or indentation script is involved | :verbose set indentexpr? cindent? autoindent? |
A minimal decision rule
- Prefer automatic bracketed paste in current Vim and Neovim.
- Prefer
"+pwhen the text is already in a working system-clipboard register. - Use
:set pastefollowed by:set nopasteonly as a Vim fallback. - Use
pastetoggleonly in Vim, and only when the manual fallback is repeatedly necessary. - When a clean session also fails, investigate the terminal transport before changing indentation plugins.
2019 source archive (verbatim)
https://stackoverflow.com/questions/2514445/turning-off-auto-indent-when-pasting-text-into-vim
To turn off autoindent when you paste code, there’s a special “paste” mode.
Type
:set paste
Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) --.
After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.
:set nopaste
However, I always found that cumbersome. That’s why I map <F3> such that it can switch between paste and nopaste modes while editing the text! I add this to .vimrc
set pastetoggle=<F3>
Primary documentation
- Vim options: `paste` and `pastetoggle`
- Vim terminal help: bracketed paste
- Vim FAQ: pasting without unwanted indentation
- Vim startup help: `–clean`
- Neovim provider help: clipboard and paste
- Neovim deprecated features: obsolete `paste`
- Neovim 0.9 changes: `pastetoggle` removed
- Neovim Insert-mode register commands
- Neovim startup help: `–clean`
- Neovim health checks
