10

In the readline manual

# man readline

The following describes how to search backward and forward.

reverse-search-history (C-r)
Search backward starting at the current line and moving `up' through the history as necessary.  This is an incremental search.

forward-search-history (C-s)
Search forward starting at the current line and moving `down' through the  history  as  necessary.   This  is  an  incremental search.

When I hit ctrl+r and type "apt-get", I'm able to do a reverse-search-history by continually tapping ctrl+r. But then I tap ctrl+s and the terminal does not go forwards. Am I doing something incorrect?

Also what key does the Meta prefix "M-" represent?

14

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.

  • ^J is a good choice since for stop, it's not used for anything else – hobs Apr 2 '13 at 19:56
2

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.

1

forward-search-history (C-s) doesn't work (though it is in the man page).

'M-' represents the Alt key modifier.

  • 1
    Not correct the C-s part, see my answer. – enzotib Sep 5 '11 at 12:45
0

Please do not use:

stty stop ^J

but

stty stop ^P

or anything else, as ^J makes big problems with ssh. (I do not know why anyway.) After I logged in Enter and backslash were not working. or I had to type:

stty sane 
export TERM=linux

before I wanted to type

ssh root@192...

so

stty stop ^P

solved both problems at the same time.

0

You can disable XON/XOFF flow control:

stty -ixon

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

Example

0

To switch forward when using reverse search (with Ctrl-R command) :

  1. Open your .bashrc file :
    sudo gedit ~/.bashrc

  2. add this line (the letter "f" can be replaced with another not yet used by the system)

    bind '"\C-f": forward-search-history' 
    
  3. Close your file and update your .bashrc (or open another terminal) with the command :
    source ~/.bashrc or . ~/.bashrc

NOW YOU CAN MOVE FORWARD IN THE HISTORY WITH THE SHORTCUT: Ctrl+f

Working on Ubuntu 18.04 LTS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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