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 "

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 history
  • Alt-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]])
← PreviousTmux Terminal Multiplexer Guide: Sessions, Panes, and ConfigurationNext →WezTerm Configuration Guide: GPU-Accelerated Terminal with Lua Setup
\t' \ --with-nth 1,3 \ --bind 'enter:execute($EDITOR {1})'

This setup:

← PreviousTmux Terminal Multiplexer Guide: Sessions, Panes, and ConfigurationNext →WezTerm Configuration Guide: GPU-Accelerated Terminal with Lua Setup
\t' \ --with-nth 1,3 \ --bind 'enter:execute($EDITOR {1})'

This setup:

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)" }

Preview Windows & Multi-Select

Once you're comfortable with the basics, fzf offers powerful customization options that can transform your workflow. Here are some advanced techniques worth mastering.

The key to advanced fzf usage is composition — combining simple features in creative ways to solve complex problems.

Performance & Large Repos

Here are solutions to common issues you might encounter while working with fzf.

Fuzzy Search Mastery

Congratulations! You now have a solid foundation with fzf. Here are some directions to explore next:

The best way to solidify your knowledge is to use fzf in your real projects. Start small — replace one tool in your workflow, then gradually expand.

← PreviousTmux Terminal Multiplexer Guide: Sessions, Panes, and ConfigurationNext →WezTerm Configuration Guide: GPU-Accelerated Terminal with Lua Setup
\t' \ --with-nth 1,3 \ --bind 'enter:execute($EDITOR {1})'

This setup:

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)" }

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
\t' \ --with-nth 1,3 \ --bind 'enter:execute($EDITOR {1})'

This setup:

← PreviousTmux Terminal Multiplexer Guide: Sessions, Panes, and ConfigurationNext →WezTerm Configuration Guide: GPU-Accelerated Terminal with Lua Setup
\t' \ --with-nth 1,3 \ --bind 'enter:execute($EDITOR {1})'

This setup:

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)" }

Preview Windows & Multi-Select

Once you're comfortable with the basics, fzf offers powerful customization options that can transform your workflow. Here are some advanced techniques worth mastering.

The key to advanced fzf usage is composition — combining simple features in creative ways to solve complex problems.

Performance & Large Repos

Here are solutions to common issues you might encounter while working with fzf.

Fuzzy Search Mastery

Congratulations! You now have a solid foundation with fzf. Here are some directions to explore next:

The best way to solidify your knowledge is to use fzf in your real projects. Start small — replace one tool in your workflow, then gradually expand.

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