Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use reverse-i-search often, and that's cool. Sometime though when pressing Ctrl+r multiple times, I pass the command I am actually looking for. Because Ctrl+r searches backward in history, from newest to oldest, I have to:

cancel, search again and stop exactly at the command, without passing it. While in reverse-i-search prompt, is it possible to search forward, i.e. from where I stand to newest. I naively tried Ctrl+shift+r, no luck. I heard about Ctrl+g but this is not what I am expecting here. Anyone has an idea?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

The one-sentence answer: Run stty -ixon in your terminal, and then use Ctrl+S to change the search direction from backward to forward.

The exact answer likely depends on which shell you're using. However, in both bash and Zsh (and probably other shells), you can (in theory) type Ctrl+S to search forward. Thus, after hitting Ctrl+R a few too many times, you can hit Ctrl+S a few times to move to the command you actually want. Many terminals, however, trap Ctrl+S and Ctrl+Q for software flow control, so the Ctrl+S never makes it to bash; if you want bash, rather than your terminal, to read the Ctrl+S, you can disable software flow control by running stty -ixon.

share|improve this answer
    
I run bash in a gnome3 terminal. Your solution works for me, I can see (reverse-i-search) and (i-search) when toggling Ctrl+s and Ctrl+r. How can I enable software flow control back again? stty -ixon does not seem to prevent reverse search from trapping Ctrl+s –  m-ric Sep 12 '12 at 14:34
2  
You can reenable software flow control using stty ixon (without the hyphen). –  Benjamin Barenblat Sep 13 '12 at 13:55
    
Or just rebind Ctrl+C to Ctrl+X keys with $ stty stop ^X From: ruslanspivak.com/2010/11/20/… –  A.D. Apr 5 '13 at 18:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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