Difference between define-key and evil-define-key

Michael Markert markert.michael at googlemail.com
Tue Oct 11 20:37:50 CEST 2011


On 11 Oct 2011, Natan Yellin wrote:

> What is the difference between these two lines?
>
> (define-key evil-normal-state-map ",b" 'ido-switch-buffer)
> (evil-define-key 'normal ",b" 'ido-switch-buffer)

You use the first correct and second wrong.

To cite the docstring (C-h f evil-define-key):

,----
| (evil-define-key STATE KEYMAP KEY DEF &rest BINDINGS)
| 
| Create a STATE binding from KEY to DEF for KEYMAP.
| STATE is one of `normal', `insert', `visual', `replace',
| `operator', `motion' and `emacs'. The remaining arguments
| are like those of `define-key'. For example:
| 
|     (evil-define-key 'normal foo-map "a" 'bar)
| 
| This creates a binding from "a" to `bar' in Normal state,
| which is active whenever `foo-map' is active. It is possible
| to specify multiple bindings at once:
| 
|     (evil-define-key 'normal foo-map
|       "a" 'bar
|       "b" 'foo)
| 
| See also `evil-declare-key'.
`----

You miss the `KEYMAP'. To come back to the original question:
`define-key' defines a key in a keymap `evil-define-key' defines a key
in `state' whenever `keymap' is active.

So the second in a correct form would be along

   (evil-define-key 'normal 'org-mode-map ",b" 'ido-switch-buffer)
   
The functions are complementary (well you can emulate `evil-define-key'
with `define-key' yourself, but you don't want to do that).

Maybe you are interested in `evil-leader': https://github.com/cofi/evil-leader

Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
Url : https://lists.ourproject.org/pipermail/implementations-list/attachments/20111011/1e17a49e/attachment.pgp 


More information about the implementations-list mailing list