Whenever I hit Ctrl+r in my command prompt it seems like I have 10 milliseconds to finish typing whatever I'm searching for and at that point it searches for whatever I've typed so far.
It also seems to be missing commands I've typed.
Also when I hit escape after such a failed search it puts whatever dumb thing it's found on my command line. How do I get back to empty command line?
Also how do I scroll through the search results?
If this reverse-i-search can't be better, is there a better way to search my history?
The "i" in "reverse-i-search" stands for "incremental" so it searches as you type. If you want it to wait until you finish typing you can use
history-search-backward
(not bound) ornon-incremental-reverse-search-history
(bound to Meta-p). To use those functions, you type the text first then press the keystroke that invokes the function.I have
history-search-backward
bound to PgUp and ``history-search-forward` bound to PgDn.To terminate a search press Esc, as you know. To abort a search leaving an empty command line, press Ctrl-G.
If you have a very long history, could be the cause of the delay. The variables HISTSIZE and HISTFILESIZE are used by bash to set the maximum history size.
Also check the variable HISTIGNORE for ignored (i.e. not put into history) commands. For example I have it set to ignore commands such as ls or exit which i don't need in my history.
To "scroll" search results keep pressing Ctrl-r (backwards) or Ctrl-s (forward). Be careful, though, that Ctrl-s is often used to "lock" the terminal (with Ctrl-Q to unlock), so you may have to remap to something else. You can use something like
to map Ctrl-g to terminal lock and free the Ctrl-s shortcut used by bash (to search forward in history).