Escape is too far away on modern keyboards and Tab could be easily typed as Ctrl+i in terminal applications. So I found it convenient to replace them in my alacritty terminal key bindings. I am used to these replacements and want them for Emacs also. What should I do, to replace Esc with Tab and vice versa in all buffers, modes, context etc allover Emacs(including evil-mode ofc)?

I've tried this in my init.el

(define-key input-decode-map [tab] [?\e])
(define-key input-decode-map [escape] [?\t])

But this doesn't trigger insert-to-normal transition in evil mode: I am pressing tab, I am seeng ESC ESC ESC in bottom bar, but evil state remains <I>.

  • 1
    What operating system? On Linux, you can make the control (or remapped caps lock) key send an escape if you tap it instead of holding it. Not directly answering your question but it's what I do.
    – éric
    Commented Feb 12, 2021 at 17:01
  • @éric thanks, I know about xcape and xmodmap and maybe will end up using them, I am still in search of my optimal workflow. But AFAIK they make system-wide changes and I would like to have keys swapped only in terminal and Emacs
    – vatosarmat
    Commented Feb 12, 2021 at 17:21
  • 1
    FWIW, replacing ESC key bindings in Emacs is problematic. ESC is used in more ways than you might expect, including some sort of behind-the-scenes ways. You can try doing it, but you are likely to find that it's not a great idea.
    – Drew
    Commented Feb 12, 2021 at 19:07
  • A pure Emacs alternative could be to use a key chord. See stackoverflow.com/questions/19150003/…
    – éric
    Commented Feb 13, 2021 at 9:36

1 Answer 1


If I understand you correctly, most importantly, you would like <tab> to work as <escape> in various "evil states". With emacs, the way I see it, you are offered with more freedom than merely "switching" these two key strokes.

To rebind <tab> for common evil states, you can first checkout with C-h k <escape> while under different states, to see the originally bound functions. I'll list each of them below:

(evil-global-set-key 'insert (kbd "<tab>") 'evil-normal-state)
(evil-global-set-key 'replace (kbd "<tab>") 'evil-normal-state)
(evil-global-set-key 'normal (kbd "<tab>") 'evil-force-normal-state)
(evil-global-set-key 'visual (kbd "<tab>") 'evil-exit-visual-state)

NOTE: For other states like operator or motion, it's not quite relevant here. Also for operator state for instance, C-g works perfectly.

If you want buffer local behavior instead of global (or special behavior in particular buffers, major modes, etc.), you can switch to evil-local-set-key for more precise keybindings.

You can do the same for (kbd "<escape>"), and rebind to literally anything you want for each state.

See what I mean by "freedom" in emacs. Hope this is what you expect. My whole point is instead of switching ESC and TAB completely, do whatever makes the most sense for your workflow.

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.