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-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")

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs