| README.md | ||
CLI Essentials | fzf
Fuzzy finding is a corner stone of digital productivity — and fzf brings it to the command line.
Interactive vs. Non-interactive Text Matchers
fzf is not grep
fzf - interactive matcher, let's takes your input dynamically and let's you select - conceptually it is more of a picker
"find . -type f" | fzf
grep - non-interactive matcher, outputs a list of filtered results based on your input - conceptually it is more of a filter
dotnet build | grep "Error"
Interactive Matchers
you type live, they update
fzf, skim, peco, fzy, selecta
great for choosing results
Non-interactive Matchers
you type, they print results once
grep, rg, ag, ack
great for finding occurrences
What can fzf do for us?
Example: choose line from text file
items.txt
apple
banana
cherry
date
elderberry
then read as input like so
fzf < items.txt
or pipe the file into fzf like so
cat items.txt | fzf
Quick refresher: < vs. |
When I try fzf < find . -type f it tells me "zsh: no such file or directory: find".
This is because in order for < to work, we need some static text ready to be read into stdin while find . -type f just gives us console output.
use
|for console output and<for files
Practical Application
In most cases you will store a pick from your fzf results into a variable for further processing like so
choice=$(cat items.txt | fzf)
echo "You picked: $choice"
Configuring fzf
fzf can be configured via inline flags like so
fzf --color=bg+:#000000,bg:#181825,fg:#f00fff,hl:#f38ba8 --reverse
or permanently inside your ~/.zshrc by setting the FZF_DEFAULT_OPTS environment variable
# ~/.zshrc
export FZF_DEFAULT_OPTS="--color=bg+:#000000,bg:#181825,fg:#f00fff,hl:#f38ba8 --reverse"
Layout and UI
| Option | Description |
|---|---|
--height 40% |
Makes the window take 40% of the terminal height |
--reverse |
Shows the prompt at the top instead of bottom |
Behavior and matching
| Option | Description |
|---|---|
--multi |
Allow selecting multiple items (use Tab to mark) |
--exact |
Disable fuzzy, match exactly |
find the full list of options on the fzf github page
What's Next?
- In Neovim we combine fuzzy finding with search context (buffers, LSP symbols, etc.)
- Outside of Neovim the most common use case is to create workflows by using
fzfin your shell scripts, see tmux-sessionizer as an example