fzfBeginner9 min
fzf is a command-line fuzzy finder. ripgrep (rg) is the fastest code search tool. Together, they let you search your entire codebase in milliseconds — fuzzy-find files, grep content, and jump to results without leaving the terminal.
This guide integrates fzf with ripgrep so you can fuzzy-search file contents interactively, preview matches, and open results in your editor.
Install both tools:
brew install fzf ripgrepEnable shell keybindings:
# Add to ~/.zshrc or ~/.bashrc
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Or run: $(brew --prefix)/opt/fzf/installThe magic happens with rg piped into fzf. ripgrep outputs matches as JSON, fzf filters them interactively, and bat previews the file.
rg --json "pattern" | fzf --ansi \
--preview 'bat --color=always --line-range :200 {1}' \
--preview-window 'right:60%' \
--delimiter >Searching Codebases FastTurn the above into a reusable shell function:
# Add to ~/.zshrc
fzg() {
local file
file=$(rg --files | fzf \
--preview 'bat --color=always {}' \
--preview-window 'right:60%:wrap') \
&& $EDITOR "$file"
}
# Fuzzy grep content
fzg() {
local result
result=$(rg --line-number --no-heading "Searching Codebases Fast
Turn the above into a reusable shell function:
# Add to ~/.zshrc
fzg() {
local file
file=$(rg --files | fzf \
--preview 'bat --color=always {}' \
--preview-window 'right:60%:wrap') \
&& $EDITOR "$file"
}
# Fuzzy grep content
fzg() {
local result
result=$(rg --line-number --no-heading "Searching Codebases Fast
" | \
fzf --preview 'bat --color=always {1}') \
&& $EDITOR "$(echo $result | cut -d: -f1) +$(echo $result | cut -d: -f2)"
}
Ctrl-T — fuzzy-find files (fzf default keybinding)Ctrl-R — fuzzy-search command historyAlt-C — fuzzy cd into directories- Custom:
fzg "pattern" — grep and jump to results
Preview Windows & Multi-Select
Advanced integration techniques:
- Use
--multi to select multiple files and act on all of them - Add
--expect to map keys: press Ctrl-O to open, Ctrl-S to split, etc. - Integrate with Git:
git log --oneline | fzf to browse commits - Use
fd instead of find for faster file listing — pair with fzf for instant results - Set
FZF_DEFAULT_COMMAND='rg --files --hidden' to include hidden files by default
Pro tip: Set FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' for a cleaner fzf popup that doesn't take over your terminal.Performance & Large Repos
Common issues:
- Keybindings not working? Run
$(brew --prefix)/opt/fzf/install and restart your shell - No syntax highlighting in preview? Install bat:
brew install bat - fzf is slow on large repos? Use
rg --files instead of find — ripgrep respects .gitignore by default - Can't search hidden files? Add
--hidden to ripgrep or set FZF_DEFAULT_COMMAND
Fuzzy Search Mastery
You've integrated fzf with ripgrep. Next steps:
- Master ripgrep's regex patterns (see [[ripgrep Tutorial]])
- Use fzf for shell history (see [[fzf Shell History]])
- Integrate fzf with Neovim via Telescope (see [[Neovim Lua Configuration Guide]])
- Learn advanced ripgrep replace (see [[ripgrep Replace and Filters]])