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.
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
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.
-
-
$TERM doesn't work on kitty so I put
export TERM="xterm"
in .zshrc but the behavior is still taking place– CadeDec 7, 2022 at 5:46 -
echo $TERM
will print out the value of theTERM
variable. Never setTERM
to anything in your shell config files (such as.zshrc
), as that is usually how this type of bug happens. Binding something toM-[
is the other most common cause :)– db48xDec 8, 2022 at 0:20