I'd like to be able to reverse-search (CTRL+R) on zsh, but have the commands searched using more than one search term.

For example, I'd like to search through commands that included both "scp" and "hello".

I'm suspecting it's not possible without searching directly in the .histfile.


I'm not sure it's possible to do exactly what you were thinking, but you can come real close (close enough to get the job done at least).

First, you probably have something like the following in your .zshrc:

bindkey '^r' history-incremental-search-backward

And a similar one for forward search. You need to change these accordingly:

bindkey '^R' history-incremental-pattern-search-backward

Now you can use patterns in your history searches. In this case, type control-r (for backwards search), then type something like the following (press control-r again once you're done to search for your pattern):

For "scp" OR "hello" anywhere in the string:


Starting with "scp" followed by "hello" anywhere in the string:


Not every pattern you can use for globbing works (for some reason it doesn't work if you try to do a strict "AND" search with two expressions where either may come first), but that should be close enough to do what you want.

Good question, by the way.


You can use two projects/plugins:

Each of them allows multi-word incremental searching through Zshell's history. Zsh Navigation Tools also allows approximate matching and has other features. HSMW has syntax colored output – you see your history colorized.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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