Emacs: Define Key Sequence

By Xah Lee. Date: . Last updated: .

In emacs, you can define key sequences.

Suppose you want:

  ;; 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 Topic

  1. Emacs: How to Define Keys
  2. Emacs: Change Major Mode Keys
  3. Emacs: Change Minor Mode Keys
  4. Emacs: Fix Minor Mode Key Priority
  5. Emacs: Define Key Sequence
  6. Emacs: How to Bind Super Hyper Keys
  7. Emacs: How to Define Menu Key
  8. Emacs: Remapping Keys Using key-translation-map
  9. Emacs: Bind Number Pad Keys
  10. Emacs: How to Set Mouse Buttons
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.