Sometimes when I paste text from the clipboard into the terminal, the resulting text has the following characters added to the front '^[[200~'.
How can I prevent this?
Sometimes when I paste text from the clipboard into the terminal, the resulting text has the following characters added to the front '^[[200~'.
How can I prevent this?
Typing Ctrl+V in a terminal doesn't paste as you might expect. By default, programs which use the Readline library, such as
bash
, will treat the next character literally when they receive this, and not as a control code.You need to type Ctrl+Shift+V to paste text. This is handled by the terminal itself, and only that pasted text is seen by Readline.
Or, at least that used to be true.
If a program has told the terminal they understand them, as Readline has started doing by default since Ubuntu 20.04, this text will be wrapped by the terminal with paste brackets, control codes
^[[200~
and^[[201~
.Guess what happens if you type Ctrl+V immediately followed by Ctrl+Shift+V when you realized your mistake.
Yes, the opening paste bracket
^[[200~
will be pasted as text, and not interpreted as a control code.One fix for this is to tell Readline to ignore Ctrl+V. To do this, add the following to your
~/.inputrc
file (creating it if necessary):This overrides the default binding of:
The Insert key and Ctrl+Q remain bound to
quoted-insert
should you ever need this for some reason.Alternatively, if you're now thinking "What's the point of bracketed-paste?", you could instead disable it in Readline by adding to your
~/.inputrc
:But, ironically, bracketed-paste tells programs to treat that pasted text literally, and not to interpret it like keyboard input. You may or may not like this.
This allows you, for example in
bash
, to edit multiple pasted lines before they are executed, as only newlines from the keyboard cause execution of code.