Emacs evil: space as a prefix key in motion state

一个人想着一个人 提交于 2020-01-02 22:28:14

问题


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:


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)


来源:https://stackoverflow.com/questions/33061926/emacs-evil-space-as-a-prefix-key-in-motion-state

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!