A vim user trying to make the leap to emacs here. A roadblock I'm facing right now is a small convenience-remapping. These remaps aren't important, but my difficulty in making them makes me worry I'm fundamentally misunderstanding something.

The maps as I have them now:

(evil-define-key 'normal evil-normal-state-map (kbd "<key-chord> C-w C-k") 'evil-window-up)
(evil-define-key 'normal evil-normal-state-map (kbd "<key-chord> C-w C-j") 'evil-window-down)

These are meant to make the usual vim window motion commands (C-w k, C-w j, etc.) a bit more forgiving on my often rather stupid fingers. Am I missing something fundamental, still, about this? Do I need to create my own minor mode / separate keymapping just for this tiny addition?

The symptom: Even with these mappings in my .emacs, I still can't switch between windows with C-w C-k and C-w C-j keychords. The minibuffer helpfully reports that those chords are unbound.

1 Answer 1


Update: evil-define-key is for a different purpose, namely installing a keybinding for a specific Evil state involving a mode's map. For example you could configure emacs-lisp-mode to do something different with RET in insert state. As you're not making use of this, define-key with eval-after-load or with-eval-after-load is the more sensible option for customizing Evil.

Please study evil-maps.el (which you can look up from inside Emacs with M-x find-library) to know what keymaps to modify. Given this information, the correct invocations are:

(define-key evil-window-map (kbd "C-k") 'evil-window-up)
(define-key evil-window-map (kbd "C-j") 'evil-window-down)

Or if you want to do it properly, defer these forms until Evil is enabled:

(with-eval-after-load 'evil-maps
  (define-key evil-window-map (kbd "C-k") 'evil-window-up)
  (define-key evil-window-map (kbd "C-j") 'evil-window-down))

On older Emacs versions than 24.4:

(eval-after-load 'evil-maps
    (define-key evil-window-map (kbd "C-k") 'evil-window-up)
    (define-key evil-window-map (kbd "C-j") 'evil-window-down)))
  • Thank you for the fishing lesson! I've been working my way through some manuals but hadn't run across the find-library function yet. Is there a reason you use define-key directly, rather than using evil's evil-define-key?
    – matthugs
    Nov 24, 2015 at 0:31
  • Hmm well since there are no examples of using evil-define-key for specifically the evil-window-map keys in the source you've pointed me to, I suppose that suffices to explain why you use the more general define function.
    – matthugs
    Nov 24, 2015 at 1:16
  • Yes, evil-define-key is limited to state-related maps. Otherwise it desugars to define-key with `eval-after-load' and multiple keybindings in an invocation, so whether you use it for these is personal preference.
    – wasamasa
    Nov 24, 2015 at 7:46
  • After reading this bug report I've realized what the purpose of evil-define-key actually is and edited my answer appropriately.
    – wasamasa
    Nov 24, 2015 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.