fzf (Fuzzy Finder) Cheatsheet
fzf (Fuzzy Finder) Cheatsheet
Installation
| Plattform | Befehl |
|---|---|
| Ubuntu/Debian | sudo apt update && sudo apt install fzf |
| Fedora/RHEL | sudo dnf install fzf |
| Arch Linux | sudo pacman -S fzf |
| macOS (Homebrew) | brew install fzf && $(brew --prefix)/opt/fzf/install |
| Windows (Chocolatey) | choco install fzf |
| Windows (Scoop) | scoop install fzf |
| Windows (winget) | winget install fzf |
| From Source | git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install |
# Bash
echo '[ -f ~/.fzf.bash ] && source ~/.fzf.bash' >> ~/.bashrc
# Zsh
echo '[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh' >> ~/.zshrc
Grundlegende Befehle
| Befehl | Beschreibung |
|---|---|
fzf | Interaktive Fuzzy-Suche auf stdin oder Dateien starten |
vim $(fzf) | Datei in vim finden und öffnen |
| `ls \ | fzf` |
fzf --multi | Aktivieren Sie den Mehrfachauswahl-Modus (verwenden Sie Tab zum Auswählen) |
fzf --preview 'cat {}' | Dateivorschau während des Browsens anzeigen |
fzf --reverse | Ergebnisse von oben nach unten anzeigen |
fzf --height 40% | Finder-Höhe auf 40% der Bildschirmgröße setzen |
fzf --border | Rahmen um Finder-Oberfläche hinzufügen |
fzf --prompt "Select: " | Passen Sie die Eingabeaufforderung an |
fzf --exact | Verwende exaktes Matching anstelle von fuzzy Matching |
fzf +i | Groß-/Kleinschreibung-sensitive Suche aktivieren |
fzf --inline-info | Informationen inline mit der Eingabeaufforderung anzeigen |
| `find . -name “*.py” \ | fzf` |
| `ps aux \ | fzf` |
| `history \ | fzf` |
Standard-Tastenkombinationen
| Tastenbelegung | Aktion |
|---|---|
Ctrl+T | Ausgewählte Dateien/Verzeichnisse in Befehlszeile einfügen |
Ctrl+R | Suchverlauf der Befehle durchsuchen und ausgewählten Befehl einfügen |
Alt+C | Fuzzy-Verzeichnis finden und hinein wechseln |
**<Tab> | Trigger fuzzy completion (e.g., vim **<Tab>) |
Ctrl+J / Ctrl+N | Cursor nach unten bewegen |
Ctrl+K / Ctrl+P | Cursor nach oben bewegen |
Enter | Artikel auswählen und beenden |
Tab | Element im Mehrfachauswahl-Modus auswählen/abwählen |
Shift+Tab | Element im Mehrfachauswahl-Modus abwählen |
Ctrl+C / Esc | Abbrechen und beenden |
Erweiterte Nutzung
| Befehl | Beschreibung |
|---|---|
fzf --preview 'bat --color=always {}' | Vorschau mit Syntaxhervorhebung mit bat |
fzf --preview-window=right:50% | Positionsvorschau-Fenster rechts mit 50% Breite |
fzf --preview-window=hidden | Beginnen Sie mit ausgeblendetem Vorschau (umschalten mit Strg+/) |
fzf --bind 'ctrl-e:execute(vim {})' | Führe vim auf dem ausgewählten Element mit Strg+E aus |
| `fzf —bind ‘ctrl-y:execute-silent(echo {} \ | pbcopy)‘` |
fzf --delimiter=' ' --nth=2.. | Suche nur ab dem 2. Feld |
fzf --header="Select file to edit" | Kopftext zum Finder hinzufügen |
fzf --color=dark | Dunkles Farbschema verwenden |
fzf --query="initial" | Vorausgefüllte Suchanfrage |
fzf --select-1 --exit-0 | Automatisch auswählen, wenn ein Treffer, beenden wenn keine vorhanden |
fzf --expect=ctrl-d,ctrl-e | Verschiedene Exit-Codes für verschiedene Schlüssel zurückgeben |
fzf --print-query | Drucke Abfragezeichenfolge auch wenn keine Übereinstimmung |
fzf --cycle | Ergebniszyklusierung aktivieren (Umlauf) |
fzf --no-mouse | Mouse-Unterstützung deaktivieren |
fzf --algo=v2 | Verwenden Sie einen schnelleren Matching-Algorithmus für große Datensätze |
fzf --tac | Eingabereihenfolge umkehren |
fzf --no-sort | Sortierung deaktivieren, Eingabereihenfolge beibehalten |
fzf --border=rounded | Abgerundeten Rahmenstil verwenden |
fzf --sync | Verwenden Sie synchrones Filtern (kein async) |
fzf --scroll-off=5 | Ausgewähltes Element 5 Zeilen vom Rand entfernt halten |
Konfiguration
Umgebungsvariablen
Primäre Konfigurationsdatei: ~/.bashrcoder ~/.zshrc
# Default command for finding files (using fd)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
# Default options applied to all fzf invocations
export FZF_DEFAULT_OPTS='
--height 40%
--layout=reverse
--border
--inline-info
--preview "bat --style=numbers --color=always --line-range :500 {}"
--preview-window=right:50%:hidden
--bind "ctrl-/:toggle-preview"
--bind "ctrl-y:execute-silent(echo {} | pbcopy)"
'
# Ctrl+T configuration (file finder)
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="
--preview 'bat --color=always --line-range :50 {}'
--bind 'ctrl-/:change-preview-window(down|hidden|)'
"
# Alt+C configuration (directory finder)
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
export FZF_ALT_C_OPTS="
--preview 'tree -C {} | head -50'
"
# Ctrl+R configuration (history search)
export FZF_CTRL_R_OPTS="
--preview 'echo {}'
--preview-window up:3:hidden:wrap
--bind 'ctrl-/:toggle-preview'
--bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'
--color header:italic
--header 'Press CTRL-Y to copy command into clipboard'
"
Farbschema-Konfiguration
# Monokai theme
export FZF_DEFAULT_OPTS='
--color=bg+:#293739,bg:#1B1D1E,border:#808080
--color=spinner:#E6DB74,hl:#7E8E91,fg:#F8F8F2
--color=header:#7E8E91,info:#A6E22E,pointer:#A6E22E
--color=marker:#F92672,fg+:#F8F8F2,prompt:#F92672,hl+:#F92672
'
# Dracula theme
export FZF_DEFAULT_OPTS='
--color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9
--color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9
--color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6
--color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4
'
# Nord theme
export FZF_DEFAULT_OPTS='
--color=fg:#e5e9f0,bg:#3b4252,hl:#81a1c1
--color=fg+:#e5e9f0,bg+:#434c5e,hl+:#81a1c1
--color=info:#eacb8a,prompt:#bf6069,pointer:#b48dac
--color=marker:#a3be8b,spinner:#b48dac,header:#a3be8b
'
Häufige Anwendungsfälle
Anwendungsfall: Git-Branch-Auswahl
# Interactive git branch selection
git checkout $(git branch -a | fzf | sed 's/^[ *]*//' | sed 's/remotes\/origin\///')
# Or create an alias
alias gcb='git checkout $(git branch | fzf | sed "s/^[ *]*//")'
Anwendungsfall: Prozess beenden
# Find and kill process interactively
kill -9 $(ps aux | fzf | awk '{print $2}')
# Or create a function
fkill() {
local pid
pid=$(ps aux | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]; then
echo $pid | xargs kill -${1:-9}
fi
}
Anwendungsfall: SSH-Host-Auswahl
# Select from SSH config hosts
ssh $(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | fzf)
# Or create an alias
alias fssh='ssh $(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | fzf)'
Anwendungsfall: Verzeichnis-Navigation mit Verlauf
# Create a function to track and jump to directories
fcd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && cd "$dir"
}
# Jump to frequently used directories (requires z or autojump)
fz() {
local dir
dir=$(z -l 2>&1 | fzf --height 40% --nth 2.. --reverse --inline-info +s --tac --query "${*}" | sed 's/^[0-9,.]* *//')
cd "$dir"
}
Anwendungsfall: Docker-Container-Verwaltung
# Select and attach to running container
docker exec -it $(docker ps | fzf | awk '{print $1}') /bin/bash
# Select and stop containers
docker stop $(docker ps -a | fzf -m | awk '{print $1}')
# Select and remove images
docker rmi $(docker images | fzf -m | awk '{print $3}')
Anwendungsfall: Umgebungsvariablen-Betrachter
# Browse and copy environment variables
env | fzf --preview 'echo {}' --preview-window=up:3:wrap \
--bind 'enter:execute(echo {} | cut -d= -f2 | pbcopy)+abort'
Anwendungsfall: Log-Datei-Analyse
# Search through log files with preview
find /var/log -type f 2>/dev/null | fzf \
--preview 'tail -100 {}' \
--bind 'enter:execute(less {})'
# Search log content
grep -r "ERROR" /var/log 2>/dev/null | fzf \
--delimiter=: \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window +{2}-/2
Bewährte Praktiken
-
Verwenden mit fd oder ripgrep: Ersetzen
findmitfdfür schnellere Dateisuche:export FZF_DEFAULT_COMMAND='fd --type f' -
Vorschau standardmäßig aktivieren: Vorschaufenster hinzufügen, um Dateiinhalte vor der Auswahl zu sehen, was die Genauigkeit verbessert und Fehler reduziert
-
Shell-Aliase erstellen: Benutzerdefinierte Aliase für häufige Arbeitsabläufe (Git-Operationen, SSH-Verbindungen, Prozessverwaltung) erstellen, um Produktivität zu maximieren
-
Mit anderen Tools kombinieren: fzf mit
batfür Syntax-Highlighting,treefür Verzeichnisvorschauen unddeltafür Git-Diffs -
Multi-Select klug nutzen: Aktivieren
--multiModus, wenn Sie auf mehrere Elemente arbeiten müssen (Dateien löschen, mehrere Git-Dateien auschecken) -
Tastenkombinationen nutzen: Passen Sie
--bindOptionen an, um Shortcuts für häufige Aktionen zu erstellen (in Editor öffnen, in Zwischenablage kopieren, Befehle ausführen) -
Für große Datensätze optimieren: Verwenden Sie
--algo=v2und erwägen Sie--syncModus für sehr große Dateilisten zur Leistungsverbesserung -
Geeignete Höhen festlegen: Verwenden Sie
--height 40%oder ähnliches, um eine vollständige Bildschirmübernahme zu vermeiden und den Kontext Ihrer aktuellen Arbeit beizubehalten -
Farbschemata konfigurieren: Passen Sie fzf-Farben an Ihr Terminal-Design an für bessere visuelle Integration und reduzierte Augenbelastung
-
Feldtrennzeichen verwenden: Beim Parsen strukturierter Ausgaben (wie
psoderdocker), verwenden Sie--delimiterund--nth, um spezifische Spalten zu durchsuchen
Fehlerbehebung
| Problem | Lösung |
|---|---|
| Key bindings not working | Run the install script: ~/.fzf/install or source the shell integration file in your RC file |
| Slow performance with large file lists | Use fd or ripgrep instead of find: export FZF_DEFAULT_COMMAND='fd --type f' and consider --algo=v2 |
| Preview not showing file contents | Ensure preview command is correct and file is readable. Try --preview 'cat {}' or install bat for better previews |
| Colors not displaying correctly | Check terminal supports 256 colors. Use --color=16 for basic color support or adjust color scheme |
| Command not found after installation | Add fzf to PATH or restart shell. For Homebrew: ensure /usr/local/bin or /opt/homebrew/bin is in PATH |
| Unicode characters not rendering | Ensure terminal and locale support UTF-8: export LC_ALL=en_US.UTF-8 and use a Unicode-capable font |
| fzf consuming too much memory | Reduce input size or use --sync mode. Consider filtering input before piping to fzf |
| Preview window not updating | Use --preview-window=follow for auto-scrolling or toggle preview with Ctrl+/ to refresh |
| Cannot select items with mouse | Mouse support may be disabled. Remove --no-mouse option or click outside fzf and retry |
Completion not working with **<Tab> | Ensure shell integration is loaded. Check ~/.fzf.bash or ~/.fzf.zsh is sourced in your RC file |
Suchsyntax
| Syntax | Beschreibung | Beispiel |
|---|---|---|
term | Fuzzy Match | fzf with input “abc” matches “a_b_c.txt” |
'term | Exakte Übereinstimmung (Einzelanführungszeichen-Präfix) | 'abc matches only “abc” exactly |
^term | Präfix exakte Übereinstimmung | ^abc matches “abc…” but not “zabc” |
term$ | Suffix exakte Übereinstimmung | abc$ matches “…abc” but not “abcz” |
!term | Inverse Match (Ausschluss) | !test excludes lines with “test” |
term1 term2 | UND Übereinstimmung (beide erforderlich) | foo bar matches lines with both terms |
| `term1 \ | term2` | OR-Übereinstimmung (entweder erforderlich) |
Nützliche Shell-Funktionen```bash
Open file in editor with preview
fe() {
local files
files=$(fzf —query=“$1” —multi —select-1 —exit-0
—preview ‘bat —color=always —line-range :500 {}’)
[[ -n “$files” ]] && ${EDITOR:-vim} ”${files[@]}”
}
Change to directory with preview
fcd() {
local dir
dir=$(fd —type d —hidden —follow —exclude .git | fzf
—preview ‘tree -C {} | head -100’) && cd “$dir”
}
Git commit browser
fgc() {
git log —oneline —color=always | fzf —ansi
—preview ‘git show —color=always {1}’
—bind ‘enter:execute(git show {1} | less -R)’
}
Browse and install packages (Debian/Ubuntu)
fap() {
apt-cache search . | fzf —multi —preview ‘apt-cache show {1}’ |
awk ‘{print $1}’ | xargs -ro sudo apt install
}