I hit Ctrl+R pretty much every time I run a command, but after typing in a word (e.g. find) I realize that the command is not in my history so I get this as expected:
(failed reverse-i-search)`find`: cat fire.txt
Now how do I cancel the search but keep 'find' in my command line? No matter what key I press 'cat fire.txt' ends up on my command line and I have to erase and re-type my command again.
I am using Ubuntu. Thank you.
I don't know that you can do what you want exactly but you can get something vaguely close (though it sacrifices other features of reverse-i-search).
Bind a key sequence to history-search-backward
and do your searches by typing the starting word and then hitting your bound sequence.
history-search-backward ()
Search backward through the history for the string of characters between the start of the current line and the point. The search string must match at the beginning of a history line. This is a non-incremental search. By default, this command is unbound.
But that only works for commands that start with the word you are searching for (as well as not being incremental).
Update: Just found, while looking for something else, that in the bash NEWS for 4.3 there is an entry that says
b. There are new bindable commands to search the history for the string of characters between the beginning of the line and the point (history-substring-search-forward, history-substring-search-backward)
So that means with a new enough version of readline (that's in the readline section of the NEWS) you can still have the substring history search with this version.
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