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?
The sequence
C-s
is taken from the terminal driver, as you can see fromTo free up the sequence for use by readline, set the stop terminal sequence to some other sequence, as for example
or remove it altogether with
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:
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.
forward-search-history (C-s) doesn't work (though it is in the man page).
'M-' represents the Alt key modifier.
To switch forward when using reverse search (with Ctrl-R command) :
Open your .bashrc file :
sudo gedit ~/.bashrc
add this line (the letter "f" can be replaced with another not yet used by the system)
source ~/.bashrc
or. ~/.bashrc
NOW YOU CAN MOVE FORWARD IN THE HISTORY WITH THE SHORTCUT: Ctrl+f
Working on Ubuntu 18.04 LTS
Please do not use:
but
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:before I wanted to type
so
solved both problems at the same time.
You can disable XON/XOFF flow control:
in your ~/.profile or similar, then Ctrl+S will be recognized.
Example
Note that I had used
in .bashrc to enable forward search and disable the annoying "Output has been suspended by pressing Ctrl+S. Press Ctrl+Q to resume" message in Konsole when ctrl+s was pressed, but both commands individually broke the Konsole integration in Dolphin (the "F4" shortcut) in the way that I had to do ctrl+c two times to get it to even work, and the automatic "cd" commands where not being injected when graphically navigating.
So I now prefer:
It has the same effect, an all seems to work as expected ;)