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-xyz-map)
  (define-key my-xyz-map (kbd "<f6>") 'visual-line-mode)
  (define-key my-xyz-map (kbd "<f7>") 'linum-mode)
  (define-key my-xyz-map (kbd "<f8>") 'whitespace-mode)
  )

(global-set-key (kbd "<f9>") my-xyz-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
Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs