The two most expensive moments in a terminal are not typing commands. They are finding the command you used last month, and finding the file buried seven directories deep whose path you only half remember. fzf solves both with one fuzzy search box, but only if you install it in the right order. Most first attempts fail because three separate things get mixed together: the binary, the shell integration, and the key bindings.
What fzf actually does
fzf is a general-purpose fuzzy finder written in Go. Give it a list of lines on stdin, and it gives you an interactive selector: type a few non-consecutive characters, candidates are ranked by match quality, arrow keys pick one, Enter commits. That is the whole core. Everything else — Ctrl-R for history, Ctrl-T for files, Alt-C for directories — is shell glue shipped in the repository, not part of the binary itself.
This distinction matters. If you brew install fzf and then press Ctrl-R expecting a search box, nothing happens until you run the install script that wires the key bindings into your shell.
Step 1: install the binary and verify it
Download the release binary for your platform, or use a package manager. On macOS:
brew install fzf
$(brew --prefix)/opt/fzf/install
The exact install path changes between Homebrew versions. Follow the hint Homebrew prints rather than copying the line blindly.
On Debian and Ubuntu:
sudo apt install fzf
The distro package is usually several releases behind. Parameters like --scheme and some newer key binding behavior may not exist there. If you want current features, use the official binary or build from source.
On Windows, both winget install fzf and the Scoop package work. PowerShell uses a different integration script than bash and zsh, so don't copy a .bashrc snippet into your PowerShell profile.
Verify the binary before touching any config:
fzf --version
If this works but Ctrl-R still does nothing, you are in step 2 territory.
Step 2: wire up shell integration
The repository's shell/ directory contains key-bindings.bash, key-bindings.zsh, and key-bindings.fish. The install script asks whether to enable Ctrl-R, Ctrl-T, completion, and which key to use, then appends a few source lines to your .bashrc or .zshrc.
For zsh, the essential lines look like this (paths vary by install method):
source /usr/share/fzf/shell/key-bindings.zsh
source /usr/share/fzf/shell/completion.zsh
Open a new shell and press Ctrl-R. If an empty search box appears, the integration is live. If you see a garbled screen or failed to open /dev/tty, check the environment first:
echo $TERM
A dumb terminal, a minimal container image, or some jump-host sessions cannot handle the escape sequences fzf needs. That is an environment limitation, not a configuration bug.
Step 3: what the three default keys really do
| Key | Action | What it feeds fzf |
|---|---|---|
| Ctrl-R | Search command history | Your shell history file |
| Ctrl-T | Pick a file and paste its path | Recursive file list from the current directory |
| Alt-C | Pick a directory and cd into it |
Directory list under the current directory |
Ctrl-T is the one people underestimate. In a project with a deep src/components/... tree, pressing Ctrl-T and typing three letters beats six rounds of ls.
Step 4: combine it with ripgrep and git
Where fzf becomes genuinely useful is as a second-stage filter over another tool's output. Searching file contents with ripgrep and then picking one interactively looks like this:
rg --files | fzf
For content search with a preview of the matching file:
rg -l "timeout" | fzf --preview 'head -80 {}'
The --preview flag uses {} as a placeholder for the current candidate. It is the single fastest way to stop opening files you don't need.
Git branch switching is the other high-value combination. Bind it to a key of your choice:
git branch --format='%(refname:short)' | fzf | xargs git checkout
Add --preview 'git log --oneline -10 {}' if you want context before switching.
Two traps that cost real time
Package versions are not interchangeable. A newer key binding file sourced by an older binary produces subtle failures — keys that work in tutorials but not on your machine. Check fzf --version before debugging anything else.
The default keys are intrusive by design. fzf takes over Ctrl-R and Ctrl-T. If you spend most of your day in a GUI and only run two or three fixed commands in a terminal, this is a net loss: you press Ctrl-R and get an unfamiliar box instead of your shell history. Skip the shell integration and keep only the binary in that case.
How far you can customize it
The key binding scripts are plain shell files. You can edit them directly, or override bindings in your own config after sourcing them. Colors, height, preview command, and the matching algorithm are all flags: --scheme, --height, --preview, --algo.
Below that layer is the Go source. The fuzzy matching implementation lives in the source tree, and you can read it if you want to understand ranking rather than guess at it. Most users never need to go that far — changing the shell script layer covers nearly every real workflow.
A quick acceptance test
Before calling the setup done, check four things:
-
fzf --versionprints a version. - Ctrl-R opens a history search with at least one entry.
- Ctrl-T from a nested directory inserts a path you recognize.
-
rg --files | fzf --preview 'head -40 {}'shows a preview pane.
All four pass and the tool is installed correctly. Anything less means you are still mixing up binary, integration, and key bindings.
A longer Chinese walkthrough with the complete command list and the source-code layer is on my site: fzf 安装与用法:Ctrl-R 搜历史、Ctrl-T 选文件.
Top comments (0)