Álvaro Ramírez
Emacs key bindings and maps
based on masteringemacs.org.
bonus tip
prefix key, followed by c-h, lists keys in prefix.
keymap
maps key to action.
keymap found in buffer and most major modes.
keys
- undefined: self explanatory.
- prefix key: ie. c-x (part of complete key).
- complete key: complete input executes associated command.
mapping
- (define-key keymap key def): add to current buffer map.
- (local-set-key key command): add to active buffer (no map option).
- (local-unset-key key)
- (global-set-key key command): add to global keymap (all buffers).
- (global-unset-key key)
key codes
- kbd: macro transaltes human-readable key to emacs readable.
- function and navigation keys must be surrounded by <>.
- example: (kbd "c-c p") or (kbd "<f8>") of (kbd "<down>").
remapping
- use remap to replace mapping (ie. kill-line with my/kill-line).
- (define-key keymap [remap original-function] 'my-own-function).
reserved keys
- "c-c ?" generally reserved for you, but third party packages use it.
- function keys (ie. f1-f12).
- hyper and super (ancient).
lookup order
- in a nutshell: minor mode keys, local keys, global keys.
- full order:
- overriding-terminal-local-map: terminal-specific key binds.
- overriding-local-map: override all other local keymaps (avoid if possible).
- char property at point: useful for yasnippet.
- emulation-mode-map-alists: advanced multi-mode keymap.
- minor-mode-overriding-map-alist: minor modes in major modes.
- minor-mode-map-alist: as previous (preferred for minor modes) <–—
- current-local-map: buffers current local map.
- current-global-map: last place to look (ie. global).
mode hooks
- (local-set-key (kbd "c-c q") 'my-awesome-method)) in hook-method.
- for key-chord-define, use current-local-map.