Terminal GuideTerminal Guide
fzf icon

fzf

Fuzzy Finders
macOSLinuxWindows
Go

General-purpose command-line fuzzy finder.

Official Website

Features

Fuzzy SearchShell IntegrationVim PluginPreview Window

Installation

Homebrew
brew install fzf
APT (Debian/Ubuntu)
apt install fzf
Pacman (Arch)
pacman -S fzf

Why Use fzf?

fzf is a fuzzy finder that dramatically improves command-line efficiency. With fuzzy search, you can quickly find files without needing to remember exact filenames.

Ultra-Fast Search

Implemented in Go, instantly displays search results even for hundreds of thousands of files. Real-time filtering is comfortable.

Shell Integration

Provides ready-to-use key bindings including Ctrl+R for history search, Ctrl+T for file search, and Alt+C for directory navigation.

Universal Pipeline

Accepts any command output via pipe and filters it interactively. Unlimited usage possibilities.

Advanced Customization

Fine-tune preview display, colors, key bindings, and search algorithms to your preference.

Installation

Installation
# macOS (Homebrew)
brew install fzf

# Install shell integration (Important!)
$(brew --prefix)/opt/fzf/install

# Ubuntu/Debian
sudo apt install fzf

# Arch Linux
sudo pacman -S fzf

# Install via Git (Latest version)
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

Running the fzf/install script enables shell integration and key bindings.

Basic Usage

File Search

File Search
# Search for files in current directory and subdirectories
fzf

# Combine with find
find . -type f | fzf

# Search including hidden files
find . -type f -name ".*" | fzf

# Open selected file in editor
vim $(fzf)

# Multiple selection (Tab to select, Enter to confirm)
fzf -m

Pipeline Usage Examples

Pipeline
# Search command history
history | fzf

# Search and kill process
ps aux | fzf | awk '{print $2}' | xargs kill

# Switch git branch
git branch | fzf | xargs git checkout

# Select commit from git log
git log --oneline | fzf | awk '{print $1}'

# Search environment variables
env | fzf

# Select docker container
docker ps | fzf | awk '{print $1}'

fzf Output Example

> main_
24/156
> src/main.rs
src/main_test.rs
docs/maintenance.md
lib/main_module.py
test/main_spec.js

Parts matching the input query "main" are highlighted and filtered in real-time.

Shell Integration

Running the fzf install script automatically sets up the following key bindings.

Key BindingFunctionDescription
Ctrl+RHistory SearchFuzzy search command history and execute
Ctrl+TFile SearchSearch for files and insert into command line
Alt+CDirectory NavigationSearch for directory and cd into it
Shell Configuration
# Add to ~/.bashrc or ~/.zshrc
# Enable fzf shell integration
[ -f ~/.fzf.bash ] && source ~/.fzf.bash  # bash
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh    # zsh

# Use fd for faster search (if fd is installed)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'

Useful Aliases

Useful Aliases
# Add to ~/.bashrc or ~/.zshrc

# Search files with preview
alias fzfp='fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"'

# Switch git branch
alias gb='git branch | fzf | xargs git checkout'

# Interactive git add
alias ga='git status -s | fzf -m | awk "{print \$2}" | xargs git add'

# Kill process
alias fkill='ps aux | fzf | awk "{print \$2}" | xargs kill -9'

# Change directory
alias fcd='cd $(find . -type d | fzf)'

# Open recently edited file
alias fe='vim $(fzf)'

# Enter docker container via exec
alias dexec='docker exec -it $(docker ps | fzf | awk "{print \$1}") /bin/bash'

# Select SSH host
alias fssh='ssh $(grep "^Host " ~/.ssh/config | awk "{print \$2}" | fzf)'

Vim/Neovim Integration

Using the fzf.vim plugin enables fzf functionality within Vim/Neovim.

Installation

Plugin Configuration
" Using vim-plug
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

" Using packer.nvim (Neovim)
use { 'junegunn/fzf', run = ':call fzf#install()' }
use { 'junegunn/fzf.vim' }

" Using lazy.nvim (Neovim)
{ 'junegunn/fzf', build = ':call fzf#install()' },
{ 'junegunn/fzf.vim' },

Main Commands

CommandFunction
:FilesFile search (within project)
:GFilesSearch files tracked by Git
:BuffersSearch open buffers
:RgFull text search with ripgrep
:LinesSearch lines in all buffers
:HistorySearch file history
:CommandsSearch Vim commands

Key Mapping Examples

Key Mapping
" ~/.vimrc or init.vim

" File search
nnoremap <C-p> :Files<CR>
nnoremap <leader>f :Files<CR>

" Git file search
nnoremap <leader>g :GFiles<CR>

" Buffer search
nnoremap <leader>b :Buffers<CR>

" Full text search (ripgrep)
nnoremap <leader>r :Rg<CR>

" Line search
nnoremap <leader>l :Lines<CR>

" Command history
nnoremap <leader>h :History:<CR>

fzf Key Bindings

KeyAction
Ctrl+J / Ctrl+NMove to next item
Ctrl+K / Ctrl+PMove to previous item
EnterConfirm selection
TabMultiple selection (with -m option)
Ctrl+ASelect all (with -m option)
Ctrl+C / EscCancel
Ctrl+UClear input

Advanced Options

Advanced Options
# Search with preview
fzf --preview 'bat --color=always {}'

# Preview window position and size
fzf --preview 'bat --color=always {}' --preview-window=right:60%

# Sort search results (default is by score)
fzf --sort

# Exact match search (disable fuzzy search)
fzf --exact

# Multi-line display
fzf --multi

# Change layout (reverse: top to bottom)
fzf --layout=reverse

# Height limit
fzf --height=40%

# Add border
fzf --border

# Customize colors
fzf --color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9

Environment Variables

Environment Variables
# Add to ~/.bashrc or ~/.zshrc

# Default options
export FZF_DEFAULT_OPTS='
  --height=40%
  --layout=reverse
  --border
  --preview-window=right:50%
  --bind=ctrl-d:preview-page-down
  --bind=ctrl-u:preview-page-up
  --color=fg:#c0caf5,bg:#1a1b26,hl:#bb9af7
  --color=fg+:#c0caf5,bg+:#292e42,hl+:#7dcfff
  --color=info:#7aa2f7,prompt:#7dcfff,pointer:#7dcfff
  --color=marker:#9ece6a,spinner:#9ece6a,header:#9ece6a
'

# Default command (using fd)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'

# For Ctrl+T
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="--preview 'bat --color=always --line-range :500 {}'"

# For Alt+C
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"

Tips

  • Prefix the search query with ' (single quote) for exact match search (e.g., 'exact)
  • Use ^ for prefix match and $ for suffix match (e.g., ^src, .rs$)
  • Use ! for exclusion/negation search (e.g., !test excludes items with test)
  • Separate by space for AND search (e.g., src main includes both)
  • Use | for OR search (e.g., rs$ | py$)
  • Combining with fd or ripgrep enables faster and more flexible searches
  • When using tmux, set FZF_TMUX=1 to display fzf in a tmux popup
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More