^c
is a common notation for Ctrl+c where c is a (uppercase) letter or one of @[\]^_
. It designates the corresponding control character. The correspondence is that the numeric code of the control character is the numeric code of the printable character (letter or punctuation symbol) minus 64, which corresponds to setting a bit to 0 in base 2. In addition, ^?
often means character 127.
Some keys send a control character:
- Escape = Ctrl+[
- Tab = Ctrl+I
- Return (or Enter or ⏎) = Ctrl+M
- Backspace = Ctrl+? or Ctrl+H (depending on the terminal configuration)
Alt (often called Meta because that was the name of the key at that position on historical Unix machines) plus a printable character sends ^[
(escape) followed by that character.
Most function and cursor keys send an escape sequence, i.e. the character ^[
followed by some printable characters. The details depend on the terminal and its configuration. For xterm, the defaults are documented in the manual. The manual is not beginner-friendly. Here are some tips to help:
- CSI means
^[[
, i.e. escape followed by open-bracket.
- SS3 means
^[O
, i.e. escape followed by uppercase-O.
- "application mode" is something that full-screen programs usually turn on. Some keys send a different escape sequence in this mode, for historical reasons. (There are actually multiple modes but I won't go into a detailed discussion because in practice, if it matters, you can just bind the escape sequences of both modes, since there are no conflicts.)
- Modifiers (Shift, Ctrl, Alt/Meta) are indicated by a numerical code. Insert a semicolon and that number just before the last character of the escape sequence. Taking the example in the documentation: F5 sends
^[[15~
, and Shift+F5 sends ^[[15;2~
. For cursor keys that send ^[[
and one letter X, to indicate a modifier M, the escape sequence is ^[[1;MX
.
Xterm follows an ANSI standard which itself is based on historical usage dating back from physical terminals. Most modern terminal emulators follow that ANSI standard and implement some but not all of xterm's extensions. Do expect minor variations between terminals though.
Thus:
^X^I
= Ctrl+X Ctrl+I = Ctrl+X Tab
^[^@
= Ctrl+Alt+@ = Escape Ctrl+@. On most terminals, Ctrl+Space also sends ^@
so ^[^@
= Ctrl+Alt+Space = Escape Ctrl+Space.
^X^[q
= Ctrl+X Alt+q = Ctrl+X Escape q
^XQ
= Ctrl+X Shift+q
^[[A
= Up
^[[1;3A
= Alt+Up (Up, with 1;M
to indicate the modifier M). Note that many terminals don't actually send these escape sequences for Alt+cursor key.
^[[1;3D
= Alt+Left
^[[1;5C
= Ctrl+Right
There's no general, convenient way to look up the key corresponding to an escape sequence. The other way round, pressing Ctrl+V followed by a key chord at a shell prompt (or in many terminal-based editors) inserts the escape sequence literally.
See also How do keyboard input and text output work? and key bindings table?
^[^@
= Control-Alt-Space, provided that your terminal sends^[
=>Esc
when you pressMeta = Alt
. This is a whole fatuous vapid pretentious mess, also subject to runtime configurations (go read about the*SendsEscape
options in the xterm manpage). Most (but not all!) "functional" key escapes can be gathered from the output ofinfocmp
and the terminfo(5) manpage (eg.infocmp xterm | fgrep '\E[1;2H'
=>kHOM
, withkHOM
being defined asshifted home key
in the manpage. For the rest (e.g.Ctrl-Left => ^[[1;5C
), you'll have to work it out fromctlseqs.txt
and the source code. – Jan 18 '21 at 06:37xterm
manpage you're able to understand the purpose ofaltIsNotMeta
,altSendsEscape
,metaSendsEscape
,eightBitInput
and map out the perverse interactions between them, then good to you -- but have a little mercy and patience with those less fortunate than you, like me. – Jan 18 '21 at 17:37