Reputation: 10151
With zsh/oh-my-zsh/iterm2, excellent way to navigate through the terminal command history.
If I issued a command say knife cookbook upload application
few days before and to get the command, I can do k
or kni
or knif
and press the up-arrow key, it'll iterate through the commands history that starts with knife
word.
But if the similar commands have ran that starts out with knife
, I'll have to iterate over the commands using up-arrow key.
But if I wanted to search through more than one word, say to get commands with both knife node
, zsh doesn't support this and starts to show the commands that starts with just knife
.
So, is there any way to get the commands that starts with two words? so that I just type two words and pressing up-arrow key to show only those commands that starts with two words typed.
Upvotes: 7
Views: 1736
Reputation: 8370
Maybe not exactly what you're looking for, but typing C-r will open a backward command search, which will search for any string you entered, starting with the most recent. To get the second most recent, press control-r again (and so on).
Also see a related thread on superuser.
Upvotes: 1
Reputation: 53614
In addition to @Shep answer I would suggest changing <C-r>
behavior from searching just only plain strings to searching glob patterns:
bindkey "\C-r" history-incremental-pattern-search-backward
. In this case you will achieve desired result by searching for knife*node
. By the way, if you did knife node<Up>
, zsh should search for commands that start with knife node
, not just with knife
. But it won’t search for commands that contain both knife
and node
separated by other words, as well as it won’t search for commands that contain knife node
not at the start of the line (talking about history-beginning-search-backward
widget).
Upvotes: 4