3

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

fhyve
  • 323
  • 2
  • 13

1 Answers1

3

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)
Henrik
  • 982
  • 1
  • 8
  • 10
  • This was the closest I found to an answer when trying to search why I couldn't get a `use-package`'s `:bind` to interpret a leader key like "space" when binding a sequence: I was using `define-key`'s string representation (just `" "`) but apparently I needed to use `kbd`'s string representation (`"SPC "`). – mtraceur Apr 04 '23 at 23:05