Question

I'm trying to map C-[ in Emacs to do the same as C-g. I tried this:

(global-set-key "\C-[" 'keyboard-escape-quit)

But Emacs behaves strangely after remapping C-[. For example, M-x stops working and if I try to remap M-x I get the following error:

error: Key sequence M-x starts with non-prefix key ESC

Why does this happen? Is there a workaround?

Was it helpful?

Solution

C-[ is the same as ESC, the Escape key. You probably do not want to rebind ESC, since it is used in many, many, many keybindings, as a prefix key. It implements the Meta key modifier in many cases, which is probably why you say that "Emacs behaves strangely" after you rebound it (removing its prefix-key behavior). See the Emacs manual, node User Input.

As to "Is there a workaround?" -- pick another key (leave ESC alone).

And wrt ESC and C-g: See the Emacs manual, node Quitting (also node Menu Bar).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top