C.W.K.
Stream
Lesson 02 of 08 · published

fzf: Fuzzy Finder Magic

~13 min · fzf, fuzzy, history

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

The interactive line picker

fzf reads stdin, shows an interactive prompt where you type to filter, and prints the selected line(s) on stdout. Once integrated into your shell, it transforms history search, file pickers, and process selection into a single muscle-memory.

Install + integrate

brew install fzf
$(brew --prefix)/opt/fzf/install   # adds keybindings + completion

The installer adds three Ctrl bindings:

  • Ctrl+R — fuzzy history search. Replaces the default. Type any substring; matches show; Enter to run.
  • Ctrl+T — fuzzy file picker. Type at a prompt, hit Ctrl+T, pick a file, the path inserts into the command line.
  • Alt+C — fuzzy cd into a subdirectory.

Standalone use

# Pick a process to kill
kill -9 "$(ps aux | fzf | awk '{print $2}')"
# Pick a git branch
git checkout "$(git branch | fzf | tr -d ' *')"
# Open a file in your editor
$EDITOR "$(fd | fzf)"

Customizing

# Better defaults
export FZF_DEFAULT_OPTS="--height 40% --reverse --border --info=inline"
# Use fd for the file pickers (faster than find)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"

Why everyone falls in love with it

You stop typing complete filenames, complete branch names, complete PIDs. Fuzzy substring + arrow-key + Enter is faster than tab completion for almost every interactive selection task.

Code

Set up fzf shell integration·bash
brew install fzf
$(brew --prefix)/opt/fzf/install
# After restart, try Ctrl+R, Ctrl+T, Alt+C

External links

Exercise

Install fzf and run the integration script. Press Ctrl+R and search history. Press Ctrl+T and pick a file. Try git checkout $(git branch | fzf | tr -d ' *') to switch branches with fuzzy.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.