Zsh history search with arrow keys and fzf
Contents
When Zsh forgets commands after you close a window, start with the history settings. Once history persists, the arrow keys can recall commands by prefix and Ctrl+R can find a command when you only remember part of it. The original setup used Zsh and an already-installed copy of fzf on Ubuntu 24.04 LTS under WSL2.
Check what Zsh is keeping
Run these checks in an interactive Zsh session.
1echo "HISTFILE: $HISTFILE"
2echo "HISTSIZE: $HISTSIZE"
3echo "SAVEHIST: $SAVEHIST"
HISTFILE is the path to the history file, HISTSIZE is the number of events retained in memory, and SAVEHIST controls how many events the shell saves to disk. A SAVEHIST of zero explains why the next window starts without the previous window’s commands. A HISTSIZE of 30 explains why the current window remembers so little. If HISTFILE points at .bash_history, give Zsh its own file.
Keep history across sessions
Add these settings to ~/.zshrc, or update the existing assignments if your configuration already sets them.
1HISTFILE=~/.zsh_history
2HISTSIZE=100000
3SAVEHIST=100000
4
5setopt HIST_IGNORE_DUPS
6setopt HIST_IGNORE_SPACE
7setopt HIST_VERIFY
8setopt SHARE_HISTORY
HIST_IGNORE_DUPSskips consecutive duplicate commands. The same command can still appear again after an intervening command.HIST_IGNORE_SPACEomits space-prefixed commands from saved history. Keep secrets out of command lines even with this option enabled, since other processes or logs can still expose arguments.HIST_VERIFYputs history expansions such as!!back on the command line for review before execution.SHARE_HISTORYappends new commands and imports commands from other sessions using the same history file. LeaveINC_APPEND_HISTORYdisabled with this setup, sinceSHARE_HISTORYalready appends entries. See the Zsh history options.
Choose a search based on what you remember
If you remember how a command starts, bind the arrow keys to Zsh’s prefix search widgets.
1autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
2zle -N up-line-or-beginning-search
3zle -N down-line-or-beginning-search
4bindkey '^[[A' up-line-or-beginning-search
5bindkey '^[[B' down-line-or-beginning-search
Type git and press Up to recall a command that begins with git. Starting from an empty line lets you browse history in order. These bindings use common arrow-key sequences. If they have no effect, check what sequences your terminal sends and whether a shell plugin rebinds those keys later in your configuration.
If you remember a word somewhere in the command, fzf can search the full line. With fzf already installed, add the following line if your package provides the key bindings at this path. For other packages, use their documented integration. See the fzf shell integration guide.
1source /usr/share/fzf/key-bindings.zsh
Open a new Zsh window or reload the configuration with source ~/.zshrc. Try a harmless command such as git status in a Git repository. In the second window, test Up after typing git. Then clear the line and try Ctrl+R with status. In fzf, Enter puts the chosen command on the prompt, where you can review or edit it before running it.

Loading comments connects to Disqus, a third-party service. Read the privacy policy