Search code examples
emacsevil-mode

How to map "jj" to Esc in emacs Evil mode


Recently I tried Emacs and found Evil helpful to keep my vim custom. I'm used to typing "jj" to return normal mode from insert mode like many Vimers do but don't know how to make it in Evil mode.

I map it like this but seems not correct:

(define-key evil-insert-state-map (kbd "jj") 'evil-normal-state)

Solution

  • This works for me. It requires the KeyChord library:

    ;;Exit insert mode by pressing j and then j quickly
    (setq key-chord-two-keys-delay 0.5)
    (key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
    (key-chord-mode 1)
    

    It is inspired by @phils answer above and based on Simon's Coding Blog: Emacs and Unity Every Day.