To be compatible with all Spacemacs bindings, please refer to Conventions.
In brief, SPC o is reserved for user custom bindings in global-map,
and SPC m o in major modes.
Key sequences are bound to commands in Emacs in various keymaps. The most basic
map is the global-map. Setting a key binding in the global-map is achieved
with the function global-set-key. Example to bind a key to the command
forward-char:
(global-set-key (kbd "C-]") 'forward-char)
The kbd macro accepts a string describing a key sequence. The global-map is
often shadowed by other maps. For example, evil-mode defines keymaps that
target states (or modes in vim terminology). Here is an example that creates the
same binding as above but only in insert state (define-key is a built-in
function. Evil-mode has its own functions for defining keys).
(define-key evil-insert-state-map (kbd "C-]") 'forward-char)
Perhaps most importantly for Spacemacs is the use of the bind-map package to
bind keys behind a leader key.
This is where most of the Spacemacs bindings live. Binding keys behind the
leader key is achieved with the functions spacemacs/set-leader-keys and
spacemacs/set-leader-keys-for-major-mode, example:
(spacemacs/set-leader-keys "C-]" 'forward-char)
(spacemacs/set-leader-keys-for-major-mode 'emacs-lisp-mode "C-]" 'forward-char)
These functions use a macro like kbd to translate the key sequences for you.
The second function, spacemacs/set-leader-keys-for-major-mode, binds the key
only in the specified mode. The second key binding is active only when the
major mode is emacs-lisp.
Finally, one should be aware of prefix keys. Essentially, all keymaps can be
nested. Nested keymaps are used extensively in spacemacs, and in vanilla Emacs
for that matter. For example, SPC a points to key bindings for "applications",
like SPC a c for calc-dispatch. Nesting bindings is easy.
(spacemacs/declare-prefix "o" "custom")
(spacemacs/set-leader-keys "oc" 'my-custom-command)
The first line declares SPC o to be a prefix and the second binds the key
sequence SPC oc to the corresponding command. The first line is actually
unnecessary to create the prefix, but it will give your new prefix a name that
key-discovery tools can use (e.g., which-key).
Example to create binding in major mode:
(spacemacs/declare-prefix-for-mode 'org-mode "mo" "custom")
(spacemacs/set-leader-keys-for-major-mode 'org-mode "oi" 'org-id-get-create)
This would add binding as , oi and SPC moi (note that the "m" in the prefix
declaration must be include).
There is much more to say about bindings keys, but these are the basics. Keys
can be bound in your ~/.spacemacs file or in individual layers.