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

Put $5 at https://www.patreon.com/xahlee , or goto paypal.com and pay to Xah@XahLee.org . Message me on XahLee discord, say so, ask me questions.
Or 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