DRY way of remapping a key in all relevant modes

Patrick Brinich-Langlois pbrinichlanglois at gmail.com
Sun Sep 23 01:47:30 CEST 2012

> Here's another approach, as recursion is not a fine choice for elisp:
>     (defun set-in-all-evil-states (key def &optional maps)
>       (unless maps
>         (setq maps (list evil-normal-state-map
>                          evil-visual-state-map
>                          evil-insert-state-map
>                          evil-emacs-state-map)))
>       (while maps
>         (define-key (pop maps) key def)))
>     ;; usage
>     (set-in-all-evil-states "i" 'evil-forward-char)
>     ;; or
>     (set-in-all-evil-states "i" 'evil-forward-char (list evil-normal-state-map
> HTH,
> Michael

Thanks, Michael! That does help. It doesn't affect the bindings in Dired, though.
Do I have to define those bindings specifically? For example,

(evil-define-key 'normal dired-mode-map "i" 'evil-forward-char)

Or is there a better way?


More information about the implementations-list mailing list