Bash – Is it possible to change the key binding for completion in bash shell

bashkeyboard shortcutsreadline

For bash, I would to modify the tab key for completion to the escape key.
I know that key bindings are defined in /etc/inputrc.

But I don't know if something like this could work:

`"\e" : complete`

I want to do that because my users were from Solaris where the escape key does the auto-completion.

Best Answer

Yes, it is possible to change the key binding or add key bindings to the complete function. This function is typically bound by default to Tab (which is the same as Ctrl+i) and Esc followed by another Esc. However, it is not possible to bind the Esc key by itself to any Readline function. This is because the Esc key is special and serves a couple of specific purposes in Readline.

The Esc key is used as a prefix for other key sequences, so entering an Esc by itself is only setting up the initial part of a full key sequence recognized by Readline. To see the list of all Esc-prefixed sequences recognized in bash, for example:

bind -p | grep '"\\e'

Because of the way Unix terminals are handled, an Esc-prefixed key sequence is usually the same as an Alt-key combination. So Esc followed by u is exactly the same as Alt+u.

The Esc key is also used to exit out of Readline's interactive history search mode.

Related Question