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
    Commented Dec 7, 2022 at 4:50

2 Answers 2


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

binding M-[ causes mouse focus to insert characters


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.

  • I'm using kitty but I'm seeing the same error in xterm and xfce terminal
    – Cade
    Commented Dec 7, 2022 at 5:37
  • $TERM doesn't work on kitty so I put export TERM="xterm" in .zshrc but the behavior is still taking place
    – Cade
    Commented Dec 7, 2022 at 5: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
    Commented Dec 8, 2022 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.