How do you tell Ctrl + R reverse-i-search to "reset itself" and start searching from the bottom of your history every time?
Background: When using reverse-i-search in Bash, I always get stuck once it is finished searching up through the history and it cannot find any more matches. Sometimes I hit Esc and re-invoke Ctrl + R a second time, expecting it to start a fresh new search from the bottom of my history. However, the "pointer" still seems to be at the previous place it left off in my history.
The problem is, I usually do not want this behavior. If I hit Esc, and then re-invoke Ctrl + R, I would like that to indicate it should restart from the bottom again and work its way back up.
I am using Cygwin on Windows, as none of the so-far mentioned solutions work.
This question was marked as a potential duplicate question. This question is not a duplicate for the following reasons:
Ctrl+R – starts a reverse search, through the bash history, simply type characters that should be unique to the command you want to find in the history.
Instead, we can use reverse-i-search . Start typing what you remember of your command. You will see the latest command from your history that matches your search term. Press ctrl + r again to navigate through earlier entries in your history that match your search term.
My Bash works as you are expecting. Maybe hitting Ctrl + C instead of Esc can help.
Also, you can search forward using Ctrl + S.
Ctrl + S works if it does not send a "stop" to your terminal, i.e., if "stty -a" gives you "-ixon". You can change it by "stty -ixon".
Thanks to @Phil for reminder.
I never tried making this the default when hitting Esc, but Bash uses readline
for input, which accepts Emacs-style keybindings by default, so you can go to the bottom using M->
(usually either by combining Meta/Alt and > or by following the Esc key with >).
If M->
does not work because your terminal does not let you enter that, try ^G
(Ctrl and G
simultaneously). That is the "cancel" stroke in Emacs and usually works with readline
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With