fzf is a command-line fuzzy finder that transforms how you interact with your terminal. Instead of remembering exact file names or scrolling through command history, just type a few characters and fzf finds matches instantly.
Once you use it, you'll wonder how you ever navigated the terminal without it. It's the single biggest productivity boost for terminal users.
Installation
Mac (Homebrew)
brew install fzf
# Install shell integrations
$(brew --prefix)/opt/fzf/install
Ubuntu/Debian
sudo apt install fzf
Arch Linux
sudo pacman -S fzf
From Git (Any System)
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
Basic Usage
Fuzzy File Search
# Find files in current directory
fzf
# Open selected file in vim
vim $(fzf)
# Open in VS Code
code $(fzf)
Pipe Anything to fzf
# Search through command history
history | fzf
# Search through process list
ps aux | fzf
# Search through git branches
git branch | fzf
Essential Keybindings
After installation with shell integration, these keybindings are available:
| Keybinding | Function |
|---|---|
Ctrl+R | Search command history (replaces default) |
Ctrl+T | Search files and insert path at cursor |
Alt+C | Search directories and cd into selection |
💡 Pro Tip: Ctrl+R is Life-Changing
The default Ctrl+R history search is clunky. fzf's replacement lets you fuzzy search through your entire history—type any part of a command to find it instantly.
Practical Examples
Git Integration
# Checkout branch with fuzzy search
git checkout $(git branch | fzf)
# Interactive add files
git add $(git status -s | fzf -m | awk '{print $2}')
# View commit history and show diff
git log --oneline | fzf --preview 'git show {1}'
Kill Process
# Find and kill a process
kill -9 $(ps aux | fzf | awk '{print $2}')
Navigate to Directory
# cd to any directory under home
cd $(find ~ -type d | fzf)
Open Recent Files in VS Code
# Find and open recent files
code $(find . -type f -mtime -7 | fzf)
Preview Window
fzf can show previews of files as you navigate:
# Preview files with bat (or cat)
fzf --preview 'bat --color=always {}'
# Preview with syntax highlighting
fzf --preview 'head -100 {}'
Make Preview Default
Add to your ~/.bashrc or ~/.zshrc:
export FZF_DEFAULT_OPTS='--preview "bat --color=always {} 2>/dev/null || cat {}"'
Customization
Use ripgrep for Faster Search
# Install ripgrep first: brew install ripgrep
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
Custom Colors
export FZF_DEFAULT_OPTS='
--color=bg+:#363a4f,bg:#24273a,spinner:#f4dbd6,hl:#ed8796
--color=fg:#cad3f5,header:#ed8796,info:#c6a0f6,pointer:#f4dbd6
--color=marker:#f4dbd6,fg+:#cad3f5,prompt:#c6a0f6,hl+:#ed8796
'
Useful Aliases
# Add to ~/.bashrc or ~/.zshrc
# Fuzzy cd
fcd() {
cd "$(find . -type d | fzf)"
}
# Fuzzy open file
fopen() {
open "$(fzf)"
}
# Fuzzy kill process
fkill() {
kill -9 $(ps aux | fzf | awk '{print $2}')
}
# Fuzzy git checkout
gco() {
git checkout $(git branch | fzf | tr -d ' ')
}
⚠️ Performance on Large Directories
In directories with millions of files, fzf can be slow. Use fd or ripgrep as the default command for better performance, and exclude directories like node_modules and .git.
Advanced: Multi-Select
Select multiple items with Tab key:
# Multi-select files to delete
rm $(fzf -m)
# Multi-select files to add to git
git add $(fzf -m)
# Open multiple files in vim
vim $(fzf -m)
Alternatives to fzf
- skim (sk): Rust implementation, similar interface
- peco: Another fuzzy finder, written in Go
- zoxide: Specifically for directory jumping (works with fzf)
Conclusion
fzf transforms the terminal from a precise-typing environment into a fuzzy-searching one. You don't need to remember exact commands or file paths—just type fragments and let fzf find the match.
Start with Ctrl+R for history search. Once you see how much faster it is, you'll want to use fzf for everything else.