C-[ is equivalent to the escape key on US English keyboards, thus, any attempt at binding it will mess up M- behaviour.

Emacs seems to have no trouble telling <escape> and C-[ apart in GUI frames. The following works fine and bindings starting with M- remain to be working:

(global-set-key (kbd "<escape>") (lambda () (interactive) (message "<escape>")))

However, if I bind

(global-set-key (kbd "C-[") (lambda () (interactive) (message "C-[")))

suddenly emacs goes crazy and binding like M-x break. Moreover, pressing C-[ refuses to trigger the bound lambda. Interestingly enough, C-x @ c [ (apply modifier control to open bracket) still says C-[ is undefined.

Is there any way of binding something to C-[ without breaking emacs?


The following solution is a bit kludky, but seems to work:

Let ~/.xbindkeysrc contain the following:

"xvkbd -xsendevent -text '\[Control_L]\[F13]'"
  m:0x14 + c:34

"xvkbd -xsendevent -text '\[Control_L]\[F14]'"
  m:0x14 + c:35

Now xbindkeys will translate C-[ to C-<f13> and C-] to C-<f14>, so they can be bound in emacs freely. You will probably want to bind abort-recursive-edit to something other than C-], for example, C-S-g.

The downside is that now C-[ is broken in every application except Emacs, which could be fixed by adding some logic to test whether the key combination is being sent to emacs...

  • FWIW, I don't think there's anything special about C-]. – Malabarba Jan 31 '15 at 13:25
  • Yeah, me neither, but for some odd reason my C-] binding stopped working after I fired up Xbindkeys, so I rebound that one, too. – Kristóf Marussy Jan 31 '15 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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