fzf
Back to Terminal
fzfBeginner9 min

fzf and ripgrep Integration: Fuzzy Search Your Codebase from the Terminal

Fuzzy Search Meets Code Search

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.

Installing fzf & ripgrep

Install both tools:

brew install fzf ripgrep

Enable shell keybindings:

# Add to ~/.zshrc or ~/.bashrc
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Or run: $(brew --prefix)/opt/fzf/install

Shell Integration Setup

The 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 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 "$1" | \
fzf --preview 'bat --color=always {1}') \
&& $EDITOR "$(echo $result | cut -d: -f1) +$(echo $result | cut -d: -f2)"
}

Preview Windows & Multi-Select

Advanced integration techniques:

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:

Fuzzy Search Mastery

You've integrated fzf with ripgrep. Next steps:

← PreviousTmux Terminal Multiplexer Guide: Sessions, Panes, and ConfigurationNext →WezTerm Configuration Guide: GPU-Accelerated Terminal with Lua Setup