emacsemacs24evil-mode

Swap : and ; to make colon commands easier to type in Emacs


I just started using emacs with Evil mode. In my .vimrc file I had the following:

nnoremap  ;  :
nnoremap  :  ;

What would I put in my .emacs file to achieve the same thing in emacs evil mode?


Solution

  • This'll do it:

    (define-key evil-motion-state-map ";" #'evil-ex)
    (define-key evil-motion-state-map ":" #'evil-repeat-find-char)
    

    Place it anywhere after you've loaded evil-mode.

    EDIT: You can also use evil-define-key / evil-define-key*:

    (evil-define-key* 'motion 'global
      ";" #'evil-ex
      ":" #'evil-repeat-find-char)
    

    The difference between evil-define-key and evil-define-key* is the latter will defer the keybinds under the motion keymap is available (if it isn't already).

    You can find documentation on the function with M-x describe-function RET evil-define-key* or C-hf describe-function RET.