Skip to content

Instantly share code, notes, and snippets.

@ccdunder
Last active October 19, 2023 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccdunder/5816865 to your computer and use it in GitHub Desktop.
Save ccdunder/5816865 to your computer and use it in GitHub Desktop.
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)
)
;; https://www.gnu.org/software/emacs/manual/html_node/elisp/
;; Text-from-Minibuffer.html#Definition of minibuffer-local-map
'(minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-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)))
@ibarland
Copy link

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