When using emacs in the terminal (with evil mode) clicking on another window causes the mode of emacs to switch to insert and it starts inserting '[]' around random words in whatever buffer is open. This only happens in terminal mode and I'm not sure how to prevent.
-
Please don't post the same question to both StackOverflow and emacs.SE. Please delete one and keep the other. Thx. – Drew Dec 07 '22 at 04:50
2 Answers
The issue was that I bound M-[ and after using describe key to see what was being sent from clicking the mouse I found a question that described the inability to use M-[ as a binding in terminals

- 21
- 3
Everything that you communicate to an application inside of a terminal is sent in the form of bytes. Keyboard button presses are bytes, mouse clicks are bytes, all kinds of back–and–forth communication between the application and the terminal happens by sending bytes back and forth.
If the application and the terminal are not using exactly the same byte sequences, then this kind of miscommunication happens. The most important information to know is what value the TERM
variable has in your shell before you run Emacs, and what terminal emulator you are actually using.

- 15,741
- 1
- 19
- 23
-
-
$TERM doesn't work on kitty so I put `export TERM="xterm"` in .zshrc but the behavior is still taking place – Cade Dec 07 '22 at 05:46
-
`echo $TERM` will print out the value of the `TERM` variable. Never set `TERM` to anything in your shell config files (such as `.zshrc`), as that is usually how this type of bug happens. Binding something to `M-[` is the other most common cause :) – db48x Dec 08 '22 at 00:20