index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

23 April 2015 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:
    1. overriding-terminal-local-map: terminal-specific key binds.
    2. overriding-local-map: override all other local keymaps (avoid if possible).
    3. char property at point: useful for yasnippet.
    4. emulation-mode-map-alists: advanced multi-mode keymap.
    5. minor-mode-overriding-map-alist: minor modes in major modes.
    6. minor-mode-map-alist: as previous (preferred for minor modes) <–—
    7. current-local-map: buffers current local map.
    8. 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.