Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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
share|improve this answer
Very comprehensive answer! Many thanks! – Peter Slotko Aug 15 '13 at 10:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.