4

What's the Evil Mode equivalent of these Vim commands?

nnoremap : ;
nnoremap ; :
vnoremap : ;
vnoremap ; :
1
  • You might have some better luck describing what you want to do. Many people here have Emacs experience, but not Vim enough to know what those do.
    – zck
    Aug 22, 2016 at 4:44

1 Answer 1

14

First of all, in Emacs one thinks in keymaps and commands, not so much keys in their (original) context. Your first step would be figuring out how the commands are named in Evil's normal and visual state (F1 k), then what keymap they're bound to (just look through evil-maps.el with M-x find-library). Armed with this knowledge, accomplishing this is fairly simple:

(with-eval-after-load 'evil-maps
  (define-key evil-motion-state-map (kbd ":") 'evil-repeat-find-char)
  (define-key evil-motion-state-map (kbd ";") 'evil-ex))

If you for whatever reason are still on Emacs 24.3:

(eval-after-load 'evil-maps
  '(progn
     (define-key evil-motion-state-map (kbd ":") 'evil-repeat-find-char)
     (define-key evil-motion-state-map (kbd ";") 'evil-ex)))

You might wonder why I'm defining a remapping for motion state only, it's because Evil only maps these keys in that state, so applying your suggested changes as is would be unnecessary.

5
  • Is there a proper tutorial on making key bindings in emacs? The solution worked, but I'm still not a 100% confident on how to create my own keybindings still.
    – Yesh
    Sep 22, 2019 at 17:04
  • 1
    Here's an Evil-specific one: github.com/noctuid/evil-guide#keybindings-and-states
    – wasamasa
    Sep 22, 2019 at 18:00
  • Hi. For some reason, I'm unable to swap the keys as such. Semi-colon now works as colon, but not the other way round. Pressing shift-; still takes me to ":" prompt. I've added the three lines as the last lines in evil-maps.el ... Am I missing something??
    – Yesh
    Nov 2, 2019 at 15:43
  • Don't edit the sources of packages, add the above snippet to your init file instead.
    – wasamasa
    Nov 2, 2019 at 17:34
  • I've added it at dotspacemacs/user-init inside the dotfile, but the behaviour is still the same - both semi-colon and colon bring up the ":"
    – Yesh
    Nov 3, 2019 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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