Mapping “jk” to Escape in Emacs’ evil-mode


I’m a Vim user. But more & more these days I find that one of my favourite versions of Vim is Emacs. Specifically, its evil-mode package, which is a very good Vim emulator1.

If you get started with evil-mode, one of the first questions you might ask is, “How do I remap ESC to something more finger-friendly?” Some people like to map jj. Personally I like jk, because it rolls off the fingers a little more easily.

Anyway, there are a couple of ways to do it in Emacs. The simplest & cleanest I’ve found is to install the key-chord package:

M-x package-install

…then add this to your .emacs file:

(require 'key-chord)
(key-chord-mode 1)
(key-chord-define evil-insert-state-map  "jk" 'evil-normal-state)


How can I get undo behavior in Evil similar to Vim’s?


Since @shosti pointed out that Evil considers deviation from Vim behavior as bugs, I filed a bug and one of the authors of Evil added a new possible value for evil-want-fine-undo:

(setq evil-want-fine-undo 'fine)

With this setting, you get new undo units when moving the cursor in insert mode, but replace operations are undone in one step. As far as I can tell this is consistent with Vim. See here for details.

shareimprove this answer

Evil Mode best practice?


I used a highly customized vim, and now use an even more customized emacs. I think youll find every instance of keymapping in my keymapping config file

Keep in mind, I am rebinding stuff that real emacs users would consider heresy, so YMMV if you ever want to learn “real” emacs (I really don’t).

one thing I would recommend to any ex vimmer is this

;;; esc quits

(define-key evil-normal-state-map [escape] 'keyboard-quit)
(define-key evil-visual-state-map [escape] 'keyboard-quit)
(define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit)

so that esc actually quits pretty much anything (like pending prompts in the minibuffer)