When I press escape 4 times in a bash terminal, it displays something like this:

Display all 2837 possibilities? (y or n)

What is this feature, and how are these entries found? (On the second esc press, the terminal gives an audible alert.)

2 Answers 2

$ bind -p | grep 'complete$'
"\C-i": complete
"\M-\e": complete

This shows that the default key binding of Meta+Esc (and Ctrl+i) in Emacs command line editing mode is the Readline function complete. The Meta key is usually Esc on keyboards without an explicit Meta key. The Readline documentation for this function says

Attempt to perform completion on the text before point. The actual completion performed is application-specific. Bash, for instance, attempts completion treating the text as a variable (if the text begins with $), username (if the text begins with ~), hostname (if the text begins with @), or command (including aliases and functions) in turn. If none of these produces a match, filename completion is attempted. Gdb, on the other hand, allows completion of program functions and variables, and only attempts filename completion under certain circumstances.

Regarding your comment to Anthon's answer: No, pressing Esc twice is not the same as pressing Tab generally (unless it's in a program that maps them both to the same action, as Readline does by default). However Ctrl+i is the same as Tab, just like Ctrl+[ is the same as Esc. This means that you can do completion with Ctrl+[ Ctrl+[ in bash if you wish, as long as double Esc is bound to the Readline complete function. This is handy if you're working at a VT220 terminal, for example, which lacks the Escape key:

German VT220 keyboard

  • Kusalananda, thank you for this in-depth answer. About your last point: why is pressing Esc twice (or \M-\e) not the same as Tab in bash, if both do completion?
    – flow2k
    Sep 13, 2017 at 6:19
  • 2
    @flow2k It is the same if both Esc-Esc and Tab are bound to the complete function, which they are by default, but not generally (i.e. the key-presses are not "the same"). You can't substitute Tab with Esc-Esc everywhere, only in readline-capable programs. However, you may substitute Tab with Ctrl-i or Esc with Ctrl-[ anywhere.
    – Kusalananda
    Sep 13, 2017 at 6:21
  • A followup if I may: I don't see Tab in the output of bind -p. Why is that? Maybe because Tab is "hardcoded" and can't be bound?
    – flow2k
    Sep 13, 2017 at 6:36
  • 1
    @flow2k No, Tab is identical to Ctrl-i. Look for \C-i. This is an equivalence on the hardware level.
    – Kusalananda
    Sep 13, 2017 at 6:45
  • How to unbind this default mapping?
    – ruohola
    Jun 19, 2020 at 8:13

That is called file completion, and if you don't have any preceding command on the commandline, bash will offer you to complete all 2837 commands it knows about, both built-in and the ones found in your PATH

The are presented in sorted order

  • 1
    Interesting - so this is the same as pressing tab twice. Perhaps 2 escapes = 1 tab?
    – flow2k
    Sep 13, 2017 at 5:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .