Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 931
Gang Liang Avatar asked Dec 18 '22 03:12

Gang Liang


2 Answers

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

like image 136
EFLS Avatar answered Jan 18 '23 23:01

EFLS


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

(spacemacs/set-leader-keys "1" 'keymap)
like image 26
Gang Liang Avatar answered Jan 19 '23 00:01

Gang Liang