spacemacs: how to define a new key-binding with a leading [SPC]?
Asked Answered
H

2

10

I would like to bind a set of additional keys for spacemacs. The following statement is used:

(global-set-key (kbd "SPC-1") '(fzf/start "01-personal"))

yet it does not work that Emacs complains that SPC is not a prefix key. Just wonder how spacemacs is able to do it. Did some searches, but didn't find the information for it. Can anyone help?

Heine answered 16/10, 2017 at 19:36 Comment(1)
For one thing, (kbd "SPC-1") won't do anything useful.Marna
J
17

A more complete answer, is to first declare a prefix, and then set leader keys. For example:

 (spacemacs/declare-prefix "o" "own-menu")
 (spacemacs/set-leader-keys "os" 'ispell-buffer)

Using "o" as a prefix is a good idea, as it is guaranteed to be available for customization. Other prefixes might be used by different layers.

You can also add nested prefixes, for example I use the following to work with IDs in orgmode:

 ;; org-ids
 (spacemacs/declare-prefix "od" "id")
 (spacemacs/set-leader-keys "odc" 'org-id-copy)
 (spacemacs/set-leader-keys "odu" 'org-id-update-id-locations)

Which allows me to press SPC o d c to copy an Org header id (and create one if it doesn't already exist).

Jentoft answered 3/11, 2017 at 11:43 Comment(3)
For mode-specific prefix key: (spacemacs/declare-prefix-for-mode 'mode "p" "prefix name").India
For mode-specific leader key: (spacemacs/set-leader-keys-for-major-mode 'mode "pl" 'function).India
Partially documented here.India
H
3

Just did some further search, the right way to set such keybinding under spacemacs is:

(spacemacs/set-leader-keys "1" 'keymap)
Heine answered 16/10, 2017 at 21:43 Comment(1)
What is keymap here?India

© 2022 - 2024 — McMap. All rights reserved.