Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 930
limon Avatar asked May 13 '12 03:05

limon


3 Answers

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.

like image 181
E. Sambo Avatar answered Nov 10 '22 03:11

E. Sambo


I don't know whether it works with Evil, but for Emacs in general the KeyChord library is designed for this sort of thing.

Try it and see?

(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
like image 24
phils Avatar answered Nov 10 '22 02:11

phils


If you're using Spacemacs then I just found that this setting (added to the beginning of user-init) works very well,

(setq-default evil-escape-key-sequence "jj")

like image 16
Caoilte Avatar answered Nov 10 '22 02:11

Caoilte