$devvkit learn --librarie fzf-guide
fzf Guide
[fuzzy-finder][cli][search][productivity]
Dev Productivity
Install
# macOS brew install fzf $(brew --prefix)/opt/fzf/install # Linux sudo apt install fzf git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install # Windows: via WSL or scoop install fzf
fzf is an interactive Unix filter for any list. Pipe text to it, fuzzy-search interactively, and get your selection back. The real power comes from key bindings: Ctrl-T for files, Ctrl-R for command history, Alt-C for cd into subdirectories.
fzf integrates with everything: `vim $(fzf)` opens the selected file. `kill -9 $(ps aux | fzf | awk '{print $2}')` kills the selected process. The preview window shows file contents or git diffs as you browse.
Customize with FZF_DEFAULT_COMMAND to use fd or ripgrep for faster search. Use --preview-window for sizing, --bind for custom keybinds, and --header for labels. Install fzf-git.sh for git-specific fuzzy searches.
Basic
Basic fuzzy search— Filter any list.
cat file.txt | fzf
ls -la | fzf
ps aux | fzf | awk '{print $2}'
find . -type f | fzf
vim $(fzf)Key Bindings
Ctrl-R history— Search command history.
# After installing key bindings: # Press Ctrl-R, start typing # Shows matching commands from history # Press Enter to execute selected # Great for finding that complex docker command from last week
Ctrl-T file search— Search files anywhere.
# Press Ctrl-T in terminal # Type file pattern, fuzzy match # Press Enter - inserts file path at cursor # cd: use Alt-C to fuzzy-navigate directories # Shell integration: [ -f ~/.fzf.bash ] && source ~/.fzf.bash [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
Preview
Preview window— See file content while browsing.
fzf --preview 'cat {}'
fzf --preview 'head -50 {}'
fzf --preview 'bat --color=always {}'
fzf --preview 'git diff HEAD -- {}'
git log --oneline | fzf --preview 'git show --stat {1}'Integration
Git integration— FZF for git branches and commits.
git branch -a | fzf | tr -d '* ' | xargs git checkout
git log --oneline | fzf | awk '{print $1}' | xargs git show
# fzf-git.sh adds:
# Ctrl-G Ctrl-F for files
# Ctrl-G Ctrl-B for branches
# Ctrl-G Ctrl-T for tagsfzf + kill— Search and kill processes.
fkill() {
kill -9 $(ps aux | fzf | awk '{print $2}')
}
# Or inline:
ps aux | fzf --header "Select to kill" --bind 'enter:execute-silent(kill -9 {2})+abort'Customization
Default command with fd— Faster search.
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" # With ripgrep: export FZF_DEFAULT_COMMAND="rg --files --hidden --no-ignore-vcs"
Custom key bindings— Configure FZF keys.
export FZF_DEFAULT_OPTS=" --bind alt-enter:toggle-preview --bind ctrl-e:preview-up --bind ctrl-y:preview-down --height 60% --layout=reverse --border "