Fuzzy search.

Alright, I had heard of fzf a long time ago, but I never took the time to really understand why I would want to use it. Well, I have been missing out.

Installation and configuration

On Arch, install fzf. Then, to make it useful from the terminal, activate the key bindings and the completion:

# ~/.bashrc
fzf_files=("/usr/share/fzf/key-bindings.bash" "/usr/share/fzf/completion.bash")
for fzf_path in "${fzf_files[@]}"; do
    if [[ -f "$fzf_path" ]]; then
        source "$fzf_path"
    fi
done

Usage

The key bindings alone are super useful, when working with the terminal:

  • Alt+c: call fzf with the subdirs of the current directory and cd into the selected one.
  • Ctrl+r: fuzzy search for your history - game changer for me!
  • Ctrl+t: start typing a command (e.g., vim ) and press Ctrl+t. This triggers fzf with all files relative to the current directory and pastes the selected path.

fzf completion seems to come in two flavors:

  • Special completion, like for kill, where kill <tab> triggers the mode.
  • For a lot of commands fzf can be triggered by using a completion trigger: ls **<tab> See the complete list of supported commands with complete | grep _fzf | rev | cut -d " " -f 1 | rev. I changed the completion trigger to ~~ in my .bashrc, though: export FZF_COMPLETION_TRIGGER='~~'.

Conclusion

I’m a bit late to the party, but fuzzy completion is indeed a game changer for me when working with the terminal and beyond. In the future I will also look into completion alternatives like fzf-tab-completion.