fzf
General-purpose command-line fuzzy finder.
Official WebsiteFeatures
Installation
brew install fzfapt install fzfpacman -S fzfWhy 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
# 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/installRunning the fzf/install script enables shell integration and key bindings.
Basic Usage
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 -mPipeline Usage Examples
# 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
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 Binding | Function | Description |
|---|---|---|
| Ctrl+R | History Search | Fuzzy search command history and execute |
| Ctrl+T | File Search | Search for files and insert into command line |
| Alt+C | Directory Navigation | Search for directory and cd into it |
# 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
# 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
" 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
| Command | Function |
|---|---|
:Files | File search (within project) |
:GFiles | Search files tracked by Git |
:Buffers | Search open buffers |
:Rg | Full text search with ripgrep |
:Lines | Search lines in all buffers |
:History | Search file history |
:Commands | Search Vim commands |
Key Mapping Examples
" ~/.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
| Key | Action |
|---|---|
| Ctrl+J / Ctrl+N | Move to next item |
| Ctrl+K / Ctrl+P | Move to previous item |
| Enter | Confirm selection |
| Tab | Multiple selection (with -m option) |
| Ctrl+A | Select all (with -m option) |
| Ctrl+C / Esc | Cancel |
| Ctrl+U | Clear input |
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:#bd93f9Environment 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.,!testexcludes items with test) - •Separate by space for AND search (e.g.,
src mainincludes both) - •Use
|for OR search (e.g.,rs$ | py$) - •Combining with
fdorripgrepenables faster and more flexible searches - •When using tmux, set
FZF_TMUX=1to display fzf in a tmux popup