Skip to main content
ansicode

DECSET ?2004 — Bracketed paste mode

Wrap pasted text in distinct escape markers so apps can tell paste from typing.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[?2004h (enable) \x1b[?2004l (disable)
\\033[\033[?2004h / \033[?2004l
\\e[\e[?2004h / \e[?2004l
ESC [ESC [ ? 2 0 0 4 h / l
hex1b 5b 3f 32 30 30 34 68 / 6c

Description

When enabled, every paste from the system clipboard is delivered to the application surrounded by `\x1b[200~` (paste start) and `\x1b[201~` (paste end). This lets shells / editors / TUIs disable autoindent, syntax-completion, and shortcut bindings while consuming pasted bytes. Modern bash (5.1+), zsh, fish, vim, neovim, emacs, and ipython all consume bracketed paste. Always disable (`?2004l`) on exit; pasted content showing literal `^[[200~` markers means a TUI crashed without restoring.

Spec citation: xterm-ctlseqs (Private mode 2004)

Examples

bash
printf '\033[?2004h'  # enable\nprintf '\033[?2004l'  # disable
python
import sys; sys.stdout.write('\x1b[?2004h')
go
fmt.Print("\x1b[?2004h")
javascript
process.stdout.write('\x1b[?2004h')
c
printf("\x1b[?2004h");

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
yes
iTerm2
yes
Windows Terminal
yes
cmd.exe / ConPTY
yes
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
no
GNU screen
no

Related sequences

In the family cookbook

DEC cookbook · 4. Bracketed paste — `\x1b[?2004h`