bind -P gives me back things like

bracketed-paste-begin can be found on "\e[200~".
revert-line can be found on "\e\C-r", "\er".
previous-history can be found on "\C-p", "\eOA", "\e[A".

How do I read this stuff? Is there a complete description somewhere?

  • I think these are scan codes. Look for them. – shivams Aug 9 '19 at 16:24
  • 1
    Yes, look under the "Key Bindings" section in the readline(3) manpage. There are described all the "emacs" escapes understood by readline (\C-, \M-). If your Q is about how eg. \e[200~ relates to the actual key combo pressed, then please make the Q about that. – mosvy Aug 9 '19 at 17:40

While readline accepts several input formats for specifying key sequences as documented in readline(3) and bash(1) the output format is simpler (based on my observations):

  • \e is Escape (pressed sequentially before the following character)
  • \C- is Control (pressed simultaneously with the following character)
  • \\ is a backslash
  • \" is a double quote
  • \nnn (where nnn are 3 digits) is one Byte in octal
  • everything else is the character itself

Instead of sequentially pressing \ea one can also hold down what readline(3) calls the Meta key and type a. And analogously for the other letters. Because most modern keyboards don't have a Meta key, this can be considered mostly a historical naming. On PC keyboards the Alt key is used instead.

Longer escape sequences like \eOQ or \e[15~ are not intended to be entered manually, but they are produced by special keys on the keyboard. The mentioned examples are F2 and and F5 on my machine at the moment.

The sequence \e[200~ shown in the question is not directly produced by any function key. Terminal emulators can insert it when the user pastes text instead of typing it. (This feature is controlled by readline variable enable-bracketed-paste)

Because (especially in the 1970s and 1980s) different keyboard types produce(d) different escape sequences, readline binds many commands to several sequences. Don't expect that all of these sequences are produced by your keyboard.

To see what your keyboard and your terminal emulator produce you can use showkeys -a. Note that some keys are caught by the window manager or terminal emulator. So they will never make it into showkeys or readline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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