DRY way of remapping a key in all relevant modes

Patrick Brinich-Langlois pbrinichlanglois at gmail.com
Sat Sep 22 10:22:30 CEST 2012


Hi,

I've been using Vim with extensive remappings designed for the Colemak keyboard
layout (http://colemak.com/pub/vim/colemak.vim). I'm trying to recreate the Vim
mappings in Emacs with Evil. What's a good way of remapping a key in all
relevant contexts? For example, I want "i" mapped to evil-forward-char in
normal, visual, visual block, dired, etc. modes. I want to avoid this:

(define-key evil-normal-state-map "i" 'evil-forward-char)
(define-key
evil-visual-state-map "i" 'evil-forward-char)
(define-key
whatever-corresponds-to-dired-map "i" 'evil-forward-char)

I tried to write some Elisp to do this, but it doesn't work (Wrong type
argument):

(defun remap-all (char action states)
(if states (progn (define-key (car states) char action)
(remap-all char action (cdr states)))))
(setq states '(evil-normal-state-map evil-visual-state-map))
(remap-all "i" 'evil-forward-char states)

Thanks, Patrick




More information about the implementations-list mailing list