Strovent SystemsSign in
Reference

Pasted text shows ^[[200~ and ^[[201~: bracketed paste mode left on

200~ and 201~ around pasted text are bracketed paste markers. A program turned the mode on and the one reading now does not expect it. How to switch it off.

You paste a line into a remote session and get extra characters around it, such as:

^[[200~ls -l^[[201~

The text itself is fine. The extras are bracketed paste markers that the program reading your input did not expect.

What bracketed paste is

xterm and most terminals that follow it have a bracketed paste mode. A program on the host turns it on with the sequence ESC [ ? 2004 h and off with ESC [ ? 2004 l. While it is on, the terminal wraps every paste:

  • ESC [ 200 ~ before the pasted text
  • ESC [ 201 ~ after it

The program can then tell a paste from typing. Bash's line editor (Readline) uses this so that a pasted line is inserted as text and does not run until you press Enter. In Bash 5.1 and later this is on by default (enable-bracketed-paste).

Bash switches the mode on each time it shows a prompt and off again when it runs a command. Programs that expect pastes, such as Bash at its prompt, read the markers and hide them.

Why you see the markers

The terminal is still in the mode, but the program now reading your input does not understand it. Common reasons:

  • A program ended without switching the mode off. The connection dropped, or a shell or editor was killed while it had the mode on. The terminal keeps the mode until something turns it off.
  • You are typing into a program that reads plain input, such as cat, a read prompt in a script, or an older shell, while an earlier program left the mode on.

Fix it now

Turn the mode off from the shell prompt:

printf '\e[?2004l'

If the terminal also shows other leftovers, such as wrong colors or line-drawing letters, a full reset clears it: see Fix a terminal full of garbage after printing a binary file.

Stop a program from using it

If you would rather Bash not use bracketed paste at all, add this line to ~/.inputrc:

set enable-bracketed-paste off

To try it in the current shell first: bind 'set enable-bracketed-paste off'.

Turning it off means a pasted line that ends in a newline runs as soon as it is pasted, as it did before Bash 5.1.

Sources

Spotted a mistake? Email [email protected].