Emacs evil: space as a prefix key in motion state

2019-06-02 00:22发布

I want to be able to navigate windows with SPC h/j/k/l. I can just put (wrong, see edit)

(define-key evil-normal-state-map (kbd "SPC h") 'evil-window-left)

for normal state (or I could go and use evil-leader...), but neither of these work for doing the same thing in motion state. If I put

(define-key evil-motion-state-map (kbd "SPC h") 'evil-window-left)

then I get the error

error: Key sequence SPC h starts with non-prefix key SPC

I then tried to undefine SPC in motion state

(define-key evil-motion-state-map "SPC" nil)

but that doesn't get rid of the error.

How do I do this? I would prefer a solution that only changes the behaviour of SPC in motion state. I suspect the answer lies in define-prefix-command but the emacs wiki page is confusing.

EDIT:

That top line of code doesn't work. For some reason I thought it was working in normal mode but I'm getting the same error. So I can go use evil-leader, but that doesn't work in motion state

1条回答
▲ chillily
2楼-- · 2019-06-02 00:49

You were on the right track, trying to unset the space key, but define-key will read "SPC" as SPC, not spacebar.

It must be (kbd "SPC") or " " (they are equivalent; the former evaluates to the latter):

(define-key evil-motion-state-map " " nil)

Then these should work:

(define-key evil-motion-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-motion-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-motion-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-motion-state-map (kbd "SPC l") 'evil-window-right)
查看更多
登录 后发表回答