0

I have remapped the evil-normal-state command bound to ESC in Evil Insert mode to C-o since the escape key is more difficult to reach on my keyboard than typing C-o. Now I want to use the original meaning of the ESC key as a prefix key instead.

I tried:

(define-key evil-insert-state-map (kbd "ESC") 'ESC-prefix)

but it does not work.

Håkon Hægland
  • 3,608
  • 1
  • 20
  • 51
  • Seems to work if I use `""` instead of `"ESC"`. But it would be interesting to get an explanation for this – Håkon Hægland Jun 26 '16 at 22:56
  • Also found some other answers that could help to clarify the difference: See: [What is the difference between TAB and ?](http://emacs.stackexchange.com/q/9631/260) and [How to extend the ESC -> M- translation to non-character keys?](http://emacs.stackexchange.com/a/3993/260) – Håkon Hægland Jun 27 '16 at 07:49

1 Answers1

1

ESC is the escape character, <escape> is the symbol generated by pressing the ESC key in X. The escape character is generated when pressing something key together with the meta-key like M-x, that actually generates two key events, first the ESC event, second the x. (actually, that's only true in terminal mode since in X M-x generates a special event, but this event is mapped to ESC x). The problem is that in terminal mode the escape key does not generate <escape> but also ESC.

That said, in order to have the escape key working correctly in terminal, Evil has to catch the ESC event and possibly translate it to <escape> after some timeout (otherwise either bindings like M-x or leaving insert state with ESC would not work). In other words, the event ESC typically never reaches those keymaps because it is translated to <escape> before. The variable evil-intercept-esc can be used to customize this behavior (but only in newly created frames).

fifr
  • 91
  • 1