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?

  • 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
    Commented May 10, 2015 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
    Commented May 10, 2015 at 17:06
  • Ah, sorry I mostly missed the part about this only being about key bindings.
    – tarsius
    Commented May 10, 2015 at 17:10

2 Answers 2


(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 ()
               ,(if (string-equal key (substring seq 0 1))
                       (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")
  • Where is evil-map defined? I can't find it on Github.
    – idbrii
    Commented May 16, 2015 at 19:04
  • 1
    This is a macro added in spacemacs configuration.
    – syl20bnr
    Commented May 17, 2015 at 1:15
  • You mean if I want it, I should copy it to my .spacemacs?
    – idbrii
    Commented May 19, 2015 at 22:08
  • 1
    You should have it already if you use spacemacs, it may be only available in develop branch at this time though.
    – syl20bnr
    Commented May 20, 2015 at 16:02
(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.

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.