(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")
H
andL
mappings) worked whereas the other one didn't. The scope of this question is pretty narrow