Skip to content

Fzf

← Back to all decks

29 cards — 🟢 4 easy | 🟡 10 medium | 🔴 6 hard

🟢 Easy (4)

1. What is fzf and how does it enhance command-line workflows?

Show answer fzf is a command-line fuzzy finder that reads lines from stdin and presents an interactive, filterable selection menu. It turns any list into a searchable picker.

Who made it: Junegunn Choi created fzf in 2013. Written in Go, ~65K GitHub stars.

Name origin: fzf = FuZzy Finder. The double-z is intentional branding.

Analogy: fzf is to text lists what Spotlight is to macOS — instant fuzzy search over any content.

2. How do you perform an exact (non-fuzzy) match in fzf?

Show answer Prefix the search term with a single quote, e.g., typing 'error will only match lines containing the exact string "error".

Remember: 'exact, ^start, end$, !exclude, | or. Space = AND. Compose: ^src !test .py$

3. How do you select multiple items in fzf?

Show answer Use the --multi (or -m) flag, then press Tab to select/deselect individual items before pressing Enter.

Example: git log --oneline | fzf -m | cut -d' ' -f1 — pick commits with Tab, output SHAs.

4. What do the --height, --reverse, and --border flags do in fzf?

Show answer --height N% renders fzf inline using N% of terminal height instead of fullscreen. --reverse shows the prompt at the top (top-down list). --border draws a box around the fzf window. Combine all three for a compact inline picker.

Example: export FZF_DEFAULT_OPTS='--height 40% --reverse --border' — compact inline layout on every use.

🟡 Medium (10)

1. How do you show a live preview of the selected item in fzf?

Show answer Use the --preview flag with a command, e.g., fzf --preview 'bat --color=always {}'. The {} placeholder is replaced by the currently highlighted line.

Example: fzf --preview 'bat --color=always {}' shows syntax-highlighted content live as you navigate.

2. What three default keybindings does fzf provide after shell integration?

Show answer Ctrl-R for fuzzy command history search, Ctrl-T for fuzzy file path insertion, and Alt-C for fuzzy directory navigation (cd into selection).

Remember: R=Recall history, T=Take file, C=Change directory. Three shell-transforming keybindings.

3. What does the FZF_DEFAULT_COMMAND environment variable control?

Show answer It sets the command used to generate the input list when fzf is invoked without stdin. For example, setting it to 'fd --type f' uses fd instead of the default find.

Example: export FZF_DEFAULT_COMMAND='fd --type f --hidden' — uses fd instead of find. Faster, gitignore-aware.

4. How do you combine inverse matching with prefix matching in fzf's search syntax?

Show answer Use the ! prefix for inverse and ^ for prefix. For example, !^test excludes lines starting with "test". Tokens are space-separated and combined with AND logic.

Example: !^test .py$ = Python files NOT starting with test. Operators compose for precise filtering.

5. What does the FZF_DEFAULT_OPTS environment variable control, and give a practical example?

Show answer FZF_DEFAULT_OPTS sets default flags applied to every fzf invocation. Example: export FZF_DEFAULT_OPTS='--height 40% --reverse --border --preview-window=right:50%' gives a compact, bordered, top-down layout with preview on every use.

Remember: FZF_DEFAULT_COMMAND = what to search. FZF_DEFAULT_OPTS = how it looks. Two separate variables.

Gotcha: FZF_DEFAULT_COMMAND only applies when fzf has no stdin. If you pipe into fzf, it uses the pipe.

6. What is the ** trigger in fzf shell integration, and how do you use it?

Show answer Typing ** then pressing Tab triggers fzf completion in supported shells. Examples: vim ** fuzzy-picks a file to edit, cd ** fuzzy-picks a directory, ssh ** fuzzy-picks a host from known_hosts.

Example: vim ** fuzzy-finds files. ssh ** picks hosts. kill ** picks processes.

7. How do you select multiple items with Tab and Shift-Tab in fzf, and what flags enable it?

Show answer Pass --multi (or -m) to enable multi-select. Tab selects the current item and moves down, Shift-Tab deselects. All selected items are output on Enter, one per line. Combine with xargs for batch operations.

8. How do you add a file preview window to fzf?

Show answer Use --preview flag: fzf --preview 'cat {}' or --preview 'bat --color=always {}'. The {} placeholder is replaced with the selected item.

Example: fzf --preview 'bat --color=always --line-range :50 {}' — syntax-highlighted preview limited to 50 lines.

Gotcha: --preview runs the command for every cursor movement. Heavy commands cause lag.

Remember: {} = current selection. Use {q} for the current query string in --preview.

9. What do the default fzf keybindings Ctrl+T, Ctrl+R, and Alt+C do in bash/zsh?

Show answer Ctrl+T: paste selected file path. Ctrl+R: search command history. Alt+C: cd into selected directory. Each invokes fzf with appropriate input.

Example: --bind 'ctrl-y:execute-silent(echo {} | xclip)' copies to clipboard on Ctrl-Y.

10. How do you enable multi-select in fzf and what key triggers it?

Show answer Use fzf --multi or fzf -m. Press Tab to select/deselect items, then Enter to confirm all selections. Selected items are output one per line.

Example: git log --oneline | fzf -m | cut -d' ' -f1 — pick commits with Tab, output SHAs.

🔴 Hard (6)

1. How do you bind a custom action to a key inside fzf?

Show answer Use the --bind flag with the syntax 'key:action', e.g., --bind 'ctrl-y:execute-silent(echo {} | pbcopy)' copies the selection to clipboard on Ctrl-Y.

Example: --bind 'ctrl-y:execute-silent(echo {} | xclip)' copies to clipboard on Ctrl-Y.

2. How would you build an interactive git branch checkout using fzf?

Show answer Pipe git branch output through fzf and pass the selection to git checkout: git branch -a | fzf | xargs git checkout. Add --preview 'git log --oneline {1}' for commit preview.

Gotcha: add --preview 'git log --oneline -20 {1}' to see commits before switching branches.

3. How would you interactively switch Kubernetes namespaces using fzf?

Show answer kubectl get ns -o name | sed 's|namespace/||' | fzf | xargs kubectl config set-context --current --namespace. This lists namespaces, lets you pick one, and sets it as the current context namespace.

4. How do you control the preview window position and size in fzf?

Show answer Use --preview-window with options: --preview-window=right:60%:wrap puts it on the right at 60% width with line wrapping. Positions: up, down, left, right. Add :hidden to start collapsed (toggle with --bind 'ctrl-/:toggle-preview').

Example: --preview-window=right:60%:wrap:hidden — starts collapsed (toggle ctrl-/). No horizontal scroll.

5. How do you chain fzf with process substitution to interactively select from multiple sources?

Show answer Use process substitution or concatenation: cat <(git branch) <(git tag) | fzf pipes both branches and tags into one picker. Or: (echo "option-a"; echo "option-b"; command-output) | fzf for mixing static and dynamic sources.

Example: (git branch; git tag) | fzf picks from both branches and tags in one menu.

6. Describe how to integrate fzf with git for interactive branch switching.

Show answer Use: git branch | fzf | xargs git checkout. Or create an alias: alias gcb='git checkout $(git branch | fzf)'. The pipe feeds branch names to fzf for fuzzy selection.