fzf – Command-Line Fuzzy Finder

4.9 Stars
Version 0.46.0
3 MB

Supercharge Your Terminal with fzf Fuzzy Finder

fzf (fuzzy finder) has revolutionized command-line productivity by providing lightning-fast fuzzy searching capabilities that integrate seamlessly with shells, editors, and countless other tools. Written in Go for exceptional performance, fzf has become an essential utility for developers, system administrators, and power users who spend significant time in terminal environments.

The tool’s genius lies in its simplicity: feed it any list of items, and fzf provides an interactive interface for filtering and selecting from that list using fuzzy matching. This seemingly simple concept transforms tedious tasks like finding files, searching command history, switching git branches, or selecting processes into effortless, near-instantaneous operations.

Installation

Linux Installation

Ubuntu/Debian:

sudo apt install fzf

Fedora:

sudo dnf install fzf

Arch Linux:

sudo pacman -S fzf

Using Git (recommended for latest features):

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

macOS Installation

brew install fzf
$(brew --prefix)/opt/fzf/install

Windows Installation

choco install fzf
# or
scoop install fzf

Basic Usage

Interactive File Selection

The simplest usage pipes a file list to fzf:

find . -type f | fzf

Or use fzf’s built-in file finder:

fzf

Type to filter results using fuzzy matching. Press Enter to select and output the result.

Opening Files

Open selected file in your editor:

vim $(fzf)

Or with preview:

fzf --preview 'cat {}' | xargs vim

Fuzzy Matching Syntax

fzf supports powerful matching patterns:

# Exact match (prefix with ')
'exact

# Prefix match (suffix with $)
^prefix

# Suffix match (prefix with $)
suffix$

# Inverse match (prefix with !)
!exclude

# Multiple terms (space separated, AND logic)
term1 term2

# OR logic (use |)
term1 | term2

Shell Integration

Bash Integration

Add to ~/.bashrc:

[ -f ~/.fzf.bash ] && source ~/.fzf.bash

This enables powerful keybindings:
CTRL-T: Paste selected files/directories onto command line
CTRL-R: Search command history
ALT-C: cd into selected directory

Zsh Integration

Add to ~/.zshrc:

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

Fish Integration

fzf provides Fish integration through fzf.fish plugin:

fisher install PatrickF1/fzf.fish

Practical Examples

Enhanced History Search

CTRL-R becomes incredibly powerful with fzf, providing fuzzy search through your entire command history with preview:

export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:wrap"

Git Branch Switching

Create a function for fuzzy git branch selection:

fbr() {
  git branch --all | grep -v HEAD | fzf | sed 's/.* //' | sed 's#remotes/origin/##' | xargs git checkout
}

Usage:

fbr

Process Killing

Fuzzy select and kill processes:

fkill() {
  local pid
  pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
  if [ "x$pid" != "x" ]; then
    echo $pid | xargs kill -${1:-9}
  fi
}

Docker Container Management

Select and enter Docker containers:

dexec() {
  docker exec -it $(docker ps | sed 1d | fzf | awk '{print $1}') /bin/bash
}

SSH Host Selection

Fuzzy select SSH hosts from config:

fssh() {
  ssh $(grep "^Host " ~/.ssh/config | awk '{print $2}' | fzf)
}

Preview Window

File Preview

Show file contents while browsing:

fzf --preview 'cat {}'

With syntax highlighting using bat:

fzf --preview 'bat --style=numbers --color=always {}'

Directory Preview

Preview directory contents:

fzf --preview 'ls -la {}'

With tree view:

fzf --preview 'tree -C {} | head -100'

Custom Preview Commands

Different previews based on file type:

fzf --preview '[[ -f {} ]] && bat --style=numbers --color=always {} || tree -C {}'

Environment Variables

Default Options

Set default fzf options:

export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'

Default Command

Use faster file finders like fd:

export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'

Or ripgrep:

export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*"'

CTRL-T Options

Customize CTRL-T behavior:

export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always {}' --bind 'ctrl-/:toggle-preview'"

ALT-C Options

Customize directory switching:

export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -50'"

Editor Integration

Vim/Neovim Integration

Install fzf.vim plugin:

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

Common commands:

:Files     " Find files
:GFiles    " Git files
:Buffers   " Open buffers
:Rg        " Ripgrep search
:History   " Command history
:Commits   " Git commits

VS Code Integration

The fzf-vscode extension brings fuzzy finding to VS Code command palette and file search.

Advanced Keybindings

Multi-Select

Enable multi-select with Tab:

fzf --multi

Select multiple files for batch operations:

vim $(fzf --multi)

Custom Actions

Execute custom actions on selection:

fzf --bind 'ctrl-y:execute-silent(echo {} | pbcopy)+abort'

Toggle Preview

fzf --preview 'cat {}' --bind 'ctrl-/:toggle-preview'

Performance Optimization

Using Faster Alternatives

Replace find with fd for better performance:

fd --type f | fzf

Use ripgrep for content search:

rg --files | fzf

Limiting Results

For large directories:

find . -type f | head -10000 | fzf

Practical Workflow Functions

Complete fzf Configuration

Add to your shell config:

# fzf configuration
export FZF_DEFAULT_OPTS='
  --height 60%
  --layout=reverse
  --border
  --info=inline
  --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
'

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'

fzf represents a paradigm shift in command-line interaction, transforming the terminal from a precise-input environment into one that understands and adapts to human imprecision. For anyone seeking to dramatically improve their terminal productivity, fzf provides capabilities that quickly become indispensable.

Developer: Junegunn Choi

Download Options

Download fzf – Command-Line Fuzzy Finder

Version 0.46.0

File Size: 3 MB

Download Now
Safe & Secure

Verified and scanned for viruses

Regular Updates

Always get the latest version

24/7 Support

Help available when you need it