3

I've been using vim for a while (though I'm only a basic user) and I've been trying out Emacs (specifically spacemacs).

I have remapped H and L to go to the start / end of the line by adding the following at the end of ~/.emacs.d/spacemacs/config.el

(define-key evil-normal-state-map "H" "^")
(define-key evil-normal-state-map "L" "$")

I have other mappings in my .vimrc that I really want to transfer for familiar functionality, but I'm not sure how to do this.

For example I have tried adding the following line to ~/.emacs.d/spacemacs/config.el (which doesn't work)

(define-key evil-insert-state-map "jf" "<ESC>")

How could I transfer that and the rest of my mappings over to emacs/spacemacs?

alxndr
  • 107
  • 5
baxx
  • 137
  • 7
  • You will have to learn about Emacs and Spacemacs, by reading documentation. Nobody is going to convert your configuration for you - but if you have specific problems, then there are always people around to help you. – tarsius May 10 '15 at 17:04
  • 1
    @tarsius I'm not posting a whole config / asking anyone to do that... I'm just confused that the first example (`H` and `L` mappings) worked whereas the other one didn't. The scope of this question is pretty narrow – baxx May 10 '15 at 17:06
  • Ah, sorry I mostly missed the part about this only being about key bindings. – tarsius May 10 '15 at 17:10

2 Answers2

5

(This answer is more focused on Spacemacs, so it won't give a general answer about Vim-style mappings in Emacs.)

If you define jf in the insert-state map, then you won't be able to insert j any more. Simulating ESC in insert-state by quickly pressing a sequence of keys is a non-trivial task. There are several packages for this, keychord.el is one of them, I guess it is the best known one but there are some edge cases with evil. So for spacemacs I made the evil-escape package to support the ESC use case (and much more). You can set the sequence to jf by setting the variable evil-escape-key-sequence to "jf" in the dotspacemacs/init function of the dotfile.

There is another macro available in Spacemacs to mimic some easy remapping in VimL, it is called evil-map, the source code is:

    (defmacro evil-map (state key seq)
        "Map for a given STATE a KEY to a sequence SEQ of keys.
Can handle recursive definition only if KEY is the first key of SEQ.
Example: (evil-map visual \"<\" \"<gv\")"
        (let ((map (intern (format "evil-%S-state-map" state))))
          `(define-key ,map ,key
             (lambda ()
               (interactive)
               ,(if (string-equal key (substring seq 0 1))
                    `(progn
                       (call-interactively ',(lookup-key evil-normal-state-map key))
                       (execute-kbd-macro ,(substring seq 1)))
                  (execute-kbd-macro ,seq))))))

It can handle some recursive remapping. For now it is only used for the following:

  ;; Keep the region active when shifting
  (evil-map visual "<" "<gv")
  (evil-map visual ">" ">gv")
alxndr
  • 107
  • 5
syl20bnr
  • 2,095
  • 11
  • 21
1
(key-chord-define evil-insert-state-map "jk" 'evil-normal-state) 

Escape from insert mode

You need keychord for that, by the way. You can install it from your package manager.

ReneFroger
  • 3,855
  • 22
  • 63