Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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

       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"

share|improve this answer
    
Excellent!! That's exactly what I was looking for. Thanks @RedGrittyBrick! –  user815423426 Apr 11 '11 at 15:41
    
+1. I was looking for Ctrl code in inputrc --> ENTER = Ctrl + n. –  D.D.C Aug 17 '13 at 17:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.