views:

2035

answers:

4

Question: 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 escape 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 Escape, and then re-invoke ctrl-r, I would like that to indicate it should re-start from the bottom again and work its way back up.

Update: I guess I should have mentioned I am using Cygwin on windows, as none of the so-far mentioned solutions work.

+2  A: 

My bash works as you are expecting. Maybe hitting "ctrl+C" instead of "esc" can help.

Also, you can search forward using "ctrl+s"

edit: 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.

hayalci
ctrl-s usually sends a stop to your terminal so unless you have that reconfigured, (stty -a will give you that), your terminal will intercept that keystroke)
Phil
+1  A: 
M-> ... moves to end of history
M-< ... moves to start of history

Your left alt key is most likely your Meta key.

Man readline for more readline directives.

Phil
+4  A: 

I never tried making this the default when hitting Escape, 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 Escape key with >).

If M-> does not work because your terminal does not let you enter that, try ^G (Control and G simultaneously). That is the "cancel" stroke in Emacs and usually works with readline too.

Tom Alsberg
A: 
Danke Xie