Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .