Day: January 10, 2022

Terminal bracketed paste mode

Terminal bracketed paste mode

If you got some special characters when you paste a string into terminal, if they are at beginning or end of the string, then this could be bracketed paste mode caused issue.

Bracketed paste

The bracketed paste mode is to tell terminal that those strings are not typed in, they are pasted in. This can help software implemented action correctly, for example, auto indent mode should be disabled when pasting multiple lines into editor, such as vim.

In bracketed mode

If in bracketed mode, the ^[[200~ is added at beginning of string, the ^[[201~ is appended at end of string. For example, if paste string some test, terminal's app receives following string.

^[[200~some test^[[201~

Enable bracketed mode

To enable bracketed mode, run following command

printf "\e[?2004h"

Disable bracketed mode

To disable bracketed mode, run following command

printf "\e[?2004l"

References

Bracketed Paste Mode in Terminal