1

In the latest versions of terminals (gnome-terminal, mate-terminal, konsole, xfce4-terminal, xterm, etc), programs seem aware of whether some text is from paste or keyboard input. Specifically:

  • If I paste something into bash, the pasted text would be highlighted, and newlines don't trigger command execution.
  • If I paste something into vim, the text would be inserted into the cursor position, even if it wasn't in insert mode.

What is this feature called? How do I imitate this behavior in my own program? Could I temporarily disable this feature in these programs?

Related: Why is Terminal automatically executing my command after pasting text?

4

1 Answer 1

0

As Stéphane Chazelas's comments says, this feature is called "bracketed paste".

And from the linked page, you could use this to enable this feature:

printf '\33[?2004h'

And when everything is done, do this to revert to the state without this feature:

printf '\33[?2004l'

The pasted data will be quoted using ^[[200~...^[[201~, where ^[ is the escape character \e.

Because the latest versions of terminals also automatically sanitize pasted data to change ESC (\33 aka \e aka ^[) to U+241B , which I don't know if there is a way to disable, the pasted data won't contain ^[[201~, so it doesn't need unescaping.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.