How to forward-search-history with the reverse-i-search command (ctrl+r)?

The sequence C-s is taken from the terminal driver, as you can see from

stty -a | grep '\^S'

To free up the sequence for use by readline, set the stop terminal sequence to some other sequence, as for example

stty stop ^J

or remove it altogether with

stty stop undef

After that C-s would work in the given terminal.

Set it in ~/.bashrc to make it work in every terminal.

The M- sequence means the Alt key, as already noted.


In addition to assigning a different TTY 'stop' char as suggested above, you can remove it entirely if you don't plan to use it (I tend not to), like this:

$ stty stop undef

Then readline can use control-s for forward search and you won't get any strange behavior due to a new stop char being added.

Tags:

Command Line