Jean
Jean

Reputation: 53

How to map jh and fd to <Esc> in Doom Emacs?

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.

Upvotes: 5

Views: 3991

Answers (3)

2015 penn
2015 penn

Reputation: 21

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.)

Upvotes: 0

Li Xiu Ying
Li Xiu Ying

Reputation: 95

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

Upvotes: 0

Clay Morton
Clay Morton

Reputation: 330

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.

Upvotes: 4

Related Questions