Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

zsh

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.

like image 649
Autodidact Avatar asked Apr 07 '12 16:04

Autodidact


2 Answers

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

like image 144
ZyX Avatar answered Nov 04 '22 22:11

ZyX


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.

like image 30
Shep Avatar answered Nov 04 '22 20:11

Shep