|
|
## What is Paste Bracketing?
|
|
|
|
|
|
Paste Bracketing is a way for a terminal emulator, such as iTerm2, to communicate where text there user has pasted (e.g., with Cmd-V) begins and ends.
|
|
|
|
|
|
It is useful in a text editor that automatically adds indentation. Since pasted text is already indented, it would normally get double-indented. With paste bracketing enabled, the indentation pasted in gets preserved.
|
|
|
|
|
|
## Why did iTerm2 ask if I wanted to turn it off?
|
|
|
|
|
|
Paste bracketing must be enabled and disabled by a program (such as emacs or vim). This is done by an invisible control sequence originated by such a program. If this is done in an ssh session that unexpectedly terminates while the editor is running (such as because of a network problem) then paste bracketing is left enabled even though the program receiving input never asked it to be turned on.
|
|
|
|
|
|
The result of this unfortunate situation is garbage characters appear at the beginning and end of pasted text. The user is perplexed.
|
|
|
|
|
|
Shell Integration is able to detect when the current hostname changes, provided it is installed on both the machine you ssh from and the one you ssh to. If paste bracketing is enabled when the hostname changes, that is a red flag that an ssh session has ended unexpectedly. iTerm2 will ask if you'd like to turn it off. You almost certainly do.
|
|
|
|
|
|
## Control sequences
|
|
|
|
|
|
To enable paste bracketing, use this control sequence:
|
|
|
|
|
|
<kbd>esc</kbd>`[?2004h`
|
|
|
|
|
|
To disable:
|
|
|
|
|
|
<kbd>esc</kbd>`[?2004l`
|
|
|
|
|
|
When paste bracketing is on, pasted text is prefixed by <kbd>esc</kbd>`[200~` and followed by <kbd>esc</kbd>`[201~`.
|
|
|
|