Emacs Keys: Syntax
Find Key Syntax
- Alt+x
describe-key
-
prompt user to type a key sequence, and display the key syntax and command bound to it, if any.
key sequence can be a single key, or any sequence with modifier keys.
For example, suppose you want to know the syntax for the key press of Ctrl+Alt+t.
- Alt+x
describe-key
- press Ctrl+Alt+t, emacs prints
“C-M-t runs the command transpose-sexps”.
That means,
"C-M-t"
is the key syntax.
(Note: emacs has a lot syntax variations for a given key combination, but the one printed by describe-key
is guaranteed to work.)
once you know the key syntax, you can bind the key by:
- for emacs 29, use this
(keymap-global-set keySyntax #'cmdName)
- before emacs 29, use this
(global-set-key (kbd keySyntax) #'cmdName)
Key Syntax Examples
One Modifier
"M-a"
→ Alt+a"C-a"
→ Ctrl+a"A"
→ Shift+a"S-<f3>"
→ Shift+ F3
Function keys
"<f3>"
→ F3 key
Numberpad Keys
"<kp-3>"
→ the key 3 on number pad
Arrow and Home End Cluster Keys
"<left>"
→ left arrow"<right>"
→ right arrow"<up>"
→ up arrow"<down>"
→ down arrow
"<next>"
→ page down key"<prior>"
→ page up key
"<insert>"
→ Ins key"<delete>"
→ Del key ⌦ (forward delete)
"<home>"
"<end>"
Enter, Return, Space, Backspace Keys
<backspace>
→ backspace key ⌫"SPC"
→ Space key"<return>"
→ Enter/Return key while in GUI emacs (usually auto translated to RET)
1 Modifier + Special Key
"M-<f3>"
→ Alt+F3"C-<f3>"
→ Ctrl+F3"S-<f3>"
→ Shift+F3
"M-<up>"
→ Alt+↑"C-<up>"
→ Ctrl+↑"S-<up>"
→ Shift+↑
2 Modifier Keys
2 modifier keys pressed simultaneously, plus a letter key:
"M-A"
→ Alt+Shift+a"C-A"
→ Ctrl+Shift+a"C-M-a"
→ Ctrl+Alt+a
Example of 2 modifier keys with a digit key:
"M-#"
→ Alt+Shift+3 or Alt+#"C-#"
→ Ctrl+Shift+3 or Ctrl+#"C-M-3"
→ Ctrl+Alt+3"C-S-<kp-3>"
→ Ctrl+Shift+“number pad 3”
3 Modifier Keys
3 modifier keys pressed simultaneously:
"C-M-S-a"
→ Ctrl+Alt+Shift+a"C-M-!"
→ Ctrl+Alt+Shift+1 or Ctrl+Alt+!"C-M-S-<up>"
→ Ctrl+Alt+Shift+↑
No Modifiers
A shortcut can be created without any modifier keys.
"3"
"a"
"é"
"α"
"你"
Menu Key
Super and Hyper Keys
Key Sequence
Emacs, Change Keys
- Emacs Keys: Define Key
- Emacs Keys: Keybinding Functions (emacs 29 and emacs 28)
- Emacs Keys: Syntax
- Emacs Keys: Good and Bad Key Choices
- Emacs Keys: Swap CapsLock Control
- Emacs Keys: Meta Key
- Emacs Keys: Change Major Mode Keys
- Emacs Keys: Change Minor Mode Keys
- Emacs Keys: Minor Modes Key Priority
- Emacs Keys: Change Minibuffer Keys