I'm using emacs on MacOS (v11.4 Big Sur) installed from homebrew-emacs-plus and, every time I want to open a file for a quick edit on the terminal (on iTerm2) using emacsclient, a character gets inserted at the beginning the file (please check the attached image).

Other function keys like delete also insert sequences like [3~] and, I know there must be a simple solution I can find a direct reference to this.

How can I fix this so that I can do quick edits on directly on my terminal?


enter image description here

  • 1
    If you start your emacs with emacs -q and then start the server with M-x emacs-server and then try to edit a file with emacsclient <filename>, do you get the extra characters?
    – NickD
    Jun 15, 2021 at 3:37
  • Calling like that, emacs -q, throws some other errors but, opening with open -a Emacs --args -q, starting the server and then editing a file in the terminal do not inserts any other char!
    – Hugo
    Jun 15, 2021 at 17:31
  • 1
    Which probably means that the culprit is something in your init file. You will have to debug that and fix it. Probably the best way is to bisect your init file in order to zero in on the culprit.
    – NickD
    Jun 15, 2021 at 17:51

1 Answer 1


Following the advice from @NickD, I found the offending config on my init.el:

(global-set-key (kbd "M-[") 'insert-pair)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)


  • 2
    You made the same mistake as emacs.stackexchange.com/questions/68703/…. Your terminal sent 0x1b 0x5b 0x49, which looks to Emacs like M-[ followed by a simple I. You may want to look in the iTerm documentation for the meaning, but xterm sends it when it gains focus. When running in a terminal, Emacs comes with a keymap for M-[ that handles escape sequences coming from the terminal for things like the mouse wheel, the arrow keys, the function keys, and so on. Adding a new keybinding for M-[ breaks all of that.
    – db48x
    Nov 18, 2021 at 18:34

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.