Search your shell history with fzf
Replace the default Ctrl-R with a fuzzy history search in bash, zsh or fish using fzf's shell integration.
Updated
in short
Install fzf, load its shell integration in your rc file, then press Ctrl-R to fuzzy-search every command you have run.
The built-in reverse search shows one match at a time and only matches exact substrings. fzf's key bindings swap it for a full-screen list you can filter with a few loose characters.
This guide sets that up for bash, zsh and fish, and adds a preview so long commands stay readable.
Tools used
Before you start
- bash 4.3+, zsh 5+ or fish 3.1+
- A package manager such as Homebrew, apt or pacman
Steps
Step 1: Install fzf
Install fzf 0.48 or newer from your package manager. Older releases use a different setup script.
shbrew install fzfshfzf --versionoutput0.56.3 (Homebrew)
Step 2: Load the shell integration
Add one line to your shell's rc file. It defines the key bindings and fuzzy completion.
Use the line for your shell only.
zsh# ~/.zshrc source <(fzf --zsh)bash# ~/.bashrc eval "$(fzf --bash)"fish# ~/.config/fish/config.fish fzf --fish | sourceStep 3: Search with
Ctrl-ROpen a new shell and press
Ctrl-R. Type a few characters from anywhere in the command, use the arrow keys to pick one and press Enter to put it on the prompt.Step 4: Show long commands in a preview
Multi-line commands get cut off in the list.
FZF_CTRL_R_OPTSpasses extra options to the history picker; this adds a wrapped preview window.shexport FZF_CTRL_R_OPTS=" --preview 'echo {}' --preview-window up:3:hidden:wrap --bind 'ctrl-/:toggle-preview'"
Troubleshooting
Ctrl-Rstill shows the old search: the rc file was not reloaded. Open a new terminal or runexec $SHELL.unknown option: --zsh: your fzf is older than 0.48. Upgrade it, or source the key-bindings script your package installed.
Tips
Ctrl-Tinserts file paths andAlt-Cchanges into a directory with the same picker.
FAQ
- Does this change how history is saved?
- No. fzf only reads your existing history file; the shell still writes it.
- Can I keep the old Ctrl-R?
- Yes. Rebind it after the fzf line, for example bindkey '^R' history-incremental-search-backward in zsh.