Understanding control characters in .inputrc
My Linux account in a remote machine comes with the following pre-defined .inputrc
"\e[1~": beginning-of-line
"\e[4~": end-of-line
“\e[5~”: history-search-backward
“\e[6~”: history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case on
set bell-style visible
set expand-tilde on
set convert-meta off
set input-meta on
set output-meta on
set show-all-if-ambiguous on
set visible-stats on
I am reading the GNU bash documentation on the topic, but I haven't been able to find a section explaining what the character sequences \e[1~
, \e[5C
, \e\e[D
, etc. mean.
I think I read somewhere that \e
means the meta character
(which I think is Alt
in my keyboard), but don't understand what the other control characters [
, ~
, 5D
etc. mean.
Anybody knows of a good reference on the topic?
Solution 1:
These are ANSI control-code escape sequences that are transmitted when various non alphanumeric keys are pressed on a "terminal" keyboard.
\e means the ASCII "ESCAPE" character (octal 033 hex 1B decimal 27). Which is part of a command sequence introduction (CSI).
Escape [ 2 ~
is a character sequence transmitted when you press the key labelled "Insert" on a VT220 (or later) terminal.
Many of these conventions have been adopted in software such as xterm and Linux consoles / shells - often extended in various, sometimes incompatible ways.
The use of these sequences in bash's READLINE function is described in the man pages for readline
In the second form, "keyseq":function-name or macro, keyseq differs from keyname above in that strings denoting an entire key sequence may be specified by placing the sequence within double quotes. Some GNU Emacs style key escapes can be used, as in the following example, but the symbolic character names are not recognized. "\C-u": universal-argument "\C-x\C-r": re-read-init-file "\e[11~": "Function Key 1"
To get a list of which escape sequences correspond to which keyboard-keys, you can use a command such as infocmp -L -1
or infocmp -L -1 xterm