The forward-search-history
command would do what you want — it will perform incremental search in the forward direction, and if you are already in the incremental search mode, it will just switch the search direction while keeping the current search string.
The problem is reaching that command. The default Readline bindings contain:
"\C-r": reverse-search-history
"\C-s": forward-search-history
But C-s
is the terminal flow control character, which does not reach bash
(although it would work in programs like Emacs, which change terminal settings to disable flow control processing). Therefore the default binding is useless, and you need to bind some other key to the forward-search-history
command.
Another problem is that key bindings with the Meta modifier do not work for incremental search — the Meta modifier actualy adds the ESC prefix, and ESC terminates the incremental search even when it is removed from the isearch-terminators
variable value. Combinations with the C-x
prefix also do not work — pressing C-x
immediately terminates the incremental search. Therefore you need to bind a plain C-<key>
to the forward-search-history
command; however, all such control characters are already taken by readline commands, so you will need to sacrifice another command to free a key for forward-search-history
.
Example ~/.inputrc
to use C-t
for the forward search (replacing the transpose-chars
command):
"\C-t": forward-search-history