up-arrow key to search for 2 words given with zsh shell

shell, zsh

Solution

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).

Problem

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.

Original source