Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add Emacs Evil functionality to the minibuffer
;; option for enabling vi keys in the minibuffer
;; Addresses evil-core.el:163 TODO
(mapcar (lambda (keymap)
(evil-define-key 'insert (eval keymap) [escape] 'abort-recursive-edit)
(evil-define-key 'normal (eval keymap) [escape] 'abort-recursive-edit)
(evil-define-key 'insert (eval keymap) [return] 'exit-minibuffer)
(evil-define-key 'normal (eval keymap) [return] 'exit-minibuffer)
(evil-define-key 'insert (eval keymap) "\C-t" 'evil-normal-state)
;; Text-from-Minibuffer.html#Definition of minibuffer-local-map
(add-hook 'minibuffer-setup-hook
'(lambda ()
(set (make-local-variable 'evil-echo-state) nil)
;; (evil-set-initial-state 'mode 'insert) is the evil-proper
;; way to do this, but the minibuffer doesn't have a mode.
;; The alternative is to create a minibuffer mode (here), but
;; then it may conflict with other packages' if they do the same.
(evil-insert 1)))

This comment has been minimized.

Copy link

@ibarland ibarland commented Aug 11, 2014

Thanks, after quite a bit of searching and my own tries, this works like a charm! The only change I made is to retain ESC for exiting insert-mode (removing lines 5,6,9) -- these fingers are too old to learn a new binding for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment