3

This is probably a very simple question, but I would really like to find out if this is possible.

If I start a reverse history search with C-r and then press C-r again multiple times I can search for further cmds in the history.

When pressing C-r quickly, it often happens that I miss a cmd that I want to use, so I would like to find a way to go back to the previous cmd.

Is it possible with the current version of readline?

2 Answers 2

5

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
0
2

You can disable XON/XOFF flow control:

stty -ixon

in your ~/.profile or similar, then Ctrl+S will be recognized.

Example

1
  • 1
    @GabiDavar updated
    – Zombo
    Feb 4, 2018 at 7:52

You must log in to answer this question.

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