GNU Readline

GNU Readline is a library commonly used to provide interactive prompts in commandline applications. The two prompts that use Readline that I used the most are Bash and the Python interpreter.

Readline may be customized by adding configuration to ~/.inputrc. This page describes both customized and default behavior that I have found helpful.

Completion

Press tab repeatedly to cycle through completions

TAB:menu-complete

If there are multiple completions with a common prefix, pressing tab the first time will tab-complete the common prefix, and any subsequent tabs will cycle through the completion. If you also set colored-completion-prefix on, then the completions displayed will have the common prefix highlighted in another color.

set menu-complete-display-prefix on

If completion is ambiguous, show available completions on first TAB press

set show-all-if-ambiguous on

If a completion is a directory or a symlink to a directory, append a trailing slash

set mark-directories on
set mark-symlinked-directories on

Display completions in different colors to indicate their file type. Color definitions are taken from the LS_COLORS environment variable. You can also set visible-stats on to have a similar effect by appending a symbol to the filename.

set colored-stats on

By default, you can also use alt + * to insert all matching completions.

Cursor movement

The following are default keybinds

The default Readline behavior is for ctrl + f to jump forwards a single character (and backwards with ctrl + b), and for alt + f and alt + b to jump forward and backward over words. But I find alt awkward to reach for, so I re-bind ctrl + f and ctrl + b to jump over words:
"\C-f":forward-word
"\C-b":backward-word

Line editing

When closing a paired parenthesis, curly brace, or square bracket, flash the matching opening delimiter by briefly moving the cursor to the matching character. This only has the appearance of moving the cursor; it's completely safe to continue typing as soon as you enter the closing delimiter.

set blink-matching-paren on

The following are default keybinds

There's also alt + d to kill the next word, but since I find alt awkward to reach for, I don't use this. Instead, with ctrl + f bound to forward-word, I find it easier to use ctrl + f + w.

You can also use alt + # to comment the current line and start a new one. This is especially useful for Bash one-liners where you realize you need to do something else first, but don't want to throw away the current line. But I find it an especially awkward keypress, so I normally just use ctrl + a to move the cursor to the front and enter a # myself.

History

For reverse history search in Bash, I use FZF, which is almost equivalent to Readline's reverse-search-history (bound to ctrl + r by default). I find it to be more polished, faster (to use, not necessarily more responsive), but the Readline shortcuts described above don't work in its prompt. While this is acceptable to me, it was an immediate impediment to a colleague.

Otherwise, Readline provides some useful variables to access previous lines from its history.