Emacs: Define Key Sequence

By Xah Lee. Date: . Last updated: .

In emacs, you can define key sequences.

Suppose you want:

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

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

Add other commands you use often, for example:

Typing Symbols Without Pressing Shift

(progn
  ;; define key sequence to type symbols
  (define-prefix-command 'my-symbols-map)
  (define-key my-symbols-map (kbd "1") "!")
  (define-key my-symbols-map (kbd "2") "@")
  (define-key my-symbols-map (kbd "3") "#")
  (define-key my-symbols-map (kbd "4") "$")
  (define-key my-symbols-map (kbd "5") "%")
  (define-key my-symbols-map (kbd "6") "^")
  (define-key my-symbols-map (kbd "7") "&")
  (define-key my-symbols-map (kbd "8") "*")
  (define-key my-symbols-map (kbd "0") ")")
  (global-set-key (kbd "<f9>") my-symbols-map))

(info "(elisp) Keymaps")

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Keys

Overview

How-To

Key Tips

Emacs Pinky

Keybinding Design

Misc