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.

how-to4 steps

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

  1. Step 1: Install fzf

    Install fzf 0.48 or newer from your package manager. Older releases use a different setup script.

    sh
    brew install fzf
    sh
    fzf --version
    output
    0.56.3 (Homebrew)
  2. 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 | source
  3. Step 3: Search with Ctrl-R

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

  4. Step 4: Show long commands in a preview

    Multi-line commands get cut off in the list. FZF_CTRL_R_OPTS passes extra options to the history picker; this adds a wrapped preview window.

    sh
    export FZF_CTRL_R_OPTS="
      --preview 'echo {}' --preview-window up:3:hidden:wrap
      --bind 'ctrl-/:toggle-preview'"

Troubleshooting

  • Ctrl-R still shows the old search: the rc file was not reloaded. Open a new terminal or run exec $SHELL.
  • unknown option: --zsh: your fzf is older than 0.48. Upgrade it, or source the key-bindings script your package installed.

Tips

  • Ctrl-T inserts file paths and Alt-C changes 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.

related