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 :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 "$1" | \
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 directoriesfzg "pattern" — grep and jump to resultsAdvanced integration techniques:
--multi to select multiple files and act on all of them--expect to map keys: press Ctrl-O to open, Ctrl-S to split, etc.git log --oneline | fzf to browse commitsfd instead of find for faster file listing — pair with fzf for instant resultsFZF_DEFAULT_COMMAND='rg --files --hidden' to include hidden files by defaultFZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' for a cleaner fzf popup that doesn't take over your terminal.Common issues:
$(brew --prefix)/opt/fzf/install and restart your shellbrew install batrg --files instead of find — ripgrep respects .gitignore by default--hidden to ripgrep or set FZF_DEFAULT_COMMANDYou've integrated fzf with ripgrep. Next steps: