Emacs: Define Key Sequence

By Xah Lee. Date: . Last updated: .

In emacs, you can define key sequences.

Suppose you want:

(progn
  ;; define a prefix keymap
  (define-prefix-command 'my-f9-key-map)
  (define-key my-xyz-map (kbd "<f6>") 'visual-line-mode)
  (define-key my-xyz-map (kbd "<f7>") 'whitespace-mode)
  (define-key my-xyz-map (kbd "<f8>") 'toggle-frame-fullscreen)
  )

(global-set-key (kbd "<f9>") my-f9-key-map)

;; now, 【F9 F6】 will call visual-line-mode

Press the lead key, then you can press 【Ctrl+h】 to see all available key/commands that follows.

Why is Key Sequence Useful

You can add other commands you use, for example:

(info "(elisp) Keymaps")

Emacs Keybinding How-To

  1. How to Define Keys
  2. Change Major Mode Keys
  3. Change Minor Mode Keys
  4. Fix Minor Mode Key Priority
  5. Define Key Sequence
  6. How to Bind Super Hyper Keys
  7. How to Define Menu Key
  8. Remapping Keys Using key-translation-map
  9. How to Set Mouse Buttons

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc