Reputation: 971
I was told that in ZSH you could do something like command
and then when you hit up it would filter the history based on the given command. But when I try this it just cycles the history like bash does. Is this disabled by default?
Upvotes: 63
Views: 48219
Reputation: 12010
Hit Ctrl+r, type some letters, it will find the previous command with these letters, keep hitting Ctrl+R to continue through the previous findings.
Works in bash, zsh (and other shells i suppose).
What i personally like to have is: type some letters, press Up, the previous commands starting with the same letters appear. Very powerful, i love it.
You have to bind the keys you want to history-beginning-search-backward
and history-beginning-search-forward
.
In case it's not enough for you, zsh has a lot of options, try to look in Zsh Line Editor and tell us.
For bash, less powerful but more common, Bash commands for history.
Upvotes: 113
Reputation: 28467
We can also use fzf to fuzzy search the command history interactively.
Here is how to install:
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
Say yes to all its configs. After that, restart your zsh shell, and press Ctrl-R
, whoa, interactive command history search pops up. Enjoy!
Upvotes: 9
Reputation: 1568
If you don't want to add any keybindings, you can search by default using Ctrl+R to move backward & Ctrl+S to move forward.
You can start search with any of the key shortcuts Ctrl+R or Ctrl+S
Upvotes: 2
Reputation: 61
With the vim keybindings activated in zsh you can use vi-history-search-backward (/) when in vi command mode.
Upvotes: 6
Reputation: 4742
Use percol to dynamically search and navigate through your history with Ctrl-r.
sudo pip install percol
After a Ctrl-r, you can see your whole history in the same window. Searching for a keyword (dynamically) narrows that list down. You can use key-bindings (like this emacs like config) to navigate up and down the list and eventually make a selection.
Here is a search for all sudo install
commands available in history with sudo make install
selected.
Enter issues the selected command.
Upvotes: 7
Reputation: 271
Use exclamation point:
> !<starts-with this string>
You can arrow up/down through all commands that started with that. I use "!v" all the time to get my previous command for opening a file with Vim.
You can also use a question mark to search beyond matching the beginning of the string,
> !?status
Can find "git status".
Upvotes: 12
Reputation: 11977
That's a feature available in fish, but it seems like someone made a zsh plugin for it. It's not available in standard ZSH.
Upvotes: 4