Mac copy and paste under the terminal appears: 00~ xxx 01~ The solution to the problem

When Maccopying and pasting strings in the terminal, by chance, there will be a pair of characters at the end of the pasted string: 00~ xxx 01~.

After some research, it turns out that this is a feature of the terminal itself: bracketed paste mode .

So what is the use of this bracket paste mode? In fact, its usefulness is very simple. When the bracket paste mode is set, the pasted text is enclosed with control sequences, so that the program can distinguish the pasted text from the input text.

Then why does the terminal open brackets paste mode? In fact, most of the cases are not opened by us actively, but by some software that inadvertently opens the parenthesis paste mode.

solution

Knowing the reason, the solution is at your fingertips, just turn off the bracket paste mode in the terminal:

printf "\e[?2004l"

So what if you want to actively open the bracket paste mode? You only need to enable the parenthesis paste mode in the terminal:

printf "\e[?2004h"

When the bracket paste mode is enabled, there will be an extra pair of characters at the end of the pasted string: 00~ xxx 01~, but in general, we can turn it off.

For details about bracket paste mode, please refer to these two articles:
https://cirw.in/blog/bracketed-paste
http://www.xfree86.org/current/ctlseqs.html

Guess you like

Origin blog.csdn.net/yilovexing/article/details/128803541