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'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

1 Answer 1

up vote 1 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:

?(scp|hello)

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

scp*?(hello)

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

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.