Search code examples
emacsspacemacs

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?


Solution

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