5

I'm aware of evil-escape-sequence but from what I can tell, you can only have one keybinding set to it. I want fd and jh both to bring me to Normal state from Insert state.

I've also tried something like (map! :i "jh" #'evil-normal-mode) but with this, whenever I type j, Emacs freezes and waits for me to complete the command.

Jean
  • 53
  • 1
  • 5
  • 1
    general.el has a macro to do this. Not sure if this still works. https://github.com/noctuid/general.el#use-with-key-chord. The sexp starting with general-define-key. You can bind it in other evil states as well. – Hubisan Aug 19 '20 at 08:22

3 Answers3

4

I have done this with the keychord package. Note, this package measures the timeframe between the keystrokes in order to determine wether to trigger the paired function. This is how you can use h, j, k, l (keys that map to navigation in normal mode) for this extra functionality. Add (package! key-chord) to 'init.el' and the following code to 'config.el'.

(require 'key-chord)
(key-chord-mode t)
(key-chord-define-global "fd" 'evil-normal-state)
(key-chord-define-global "FD" 'evil-normal-state)
(key-chord-define-global "jh" 'evil-normal-state)
(key-chord-define-global "JH" 'evil-normal-state)

I added the capitalized equivalent so that you have the same functionality even when the caps lock is on.

Clay Morton
  • 333
  • 2
  • 15
0

For doom emacs ,

In package.el as opened by spc-f-p

put (package! key-chord) to install package.

to remap i found this helpful https://stackoverflow.com/a/13543550/14183927

Li Xiu Ying
  • 95
  • 3
  • 9
0

If you do not want to use key-chord, there is another way:

(defun evil-insert-jk-for-normal-mode ()
  (interactive)
  (insert "j")
  (let ((event (read-event nil)))
    (if (= event ?k)
      (progn
        (backward-delete-char 1)
        (evil-normal-state))
      (push event unread-command-events))))
(define-key evil-insert-state-map "j" 'evil-insert-jk-for-normal-mode)

(Tested in doom-emacs v3.0.0-alpha.)

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
2015 penn
  • 21
  • 3