Phases

What We Do

Company

Resources

Events

Blog

Hire Us

ahoy@headway.io

(920) 309 - 5605

3 min
Finding a Needle in a Haystack with FZF
Subscribe

Finding a Needle in a Haystack with FZF

Noah Settersten
Developer

A fast and customizable fuzzy finder for Vim

Trying to find specific items in your codebase

As a developer, I’m often bouncing between numerous files, looking for a specific item in a massive codebase, or trying to remember that arcane command I ran once months ago.

There are a handful of fuzzy find tools, either from builtin editor features or via the shell, but they often suffer from unfortunate limitations. Whether slow performance or having cache results get out of date, they often require accepting tradeoffs.

FZF - quickly find what you need in Vim

Enter FZF, a modern fuzzy finder written in Go that is not only incredibly fast but also very customizable.

With shell bindings and the ability to tie into Vim, it’s sped up our workflow at Headway quite a bit. Searching for a file by name in a project is nearly instantaneous, and it’s easy to pull up a command in your shell history with a few keystrokes.

Here’s how I’m using it in my environment:

Installing and managing FZF for Vim

I manage my Vim plugins using vim-plug which is a simple manager that installs plugins in parallel. It also has the ability to run post-install hooks to manage external libraries. Using it to install and manage FZF is straightforward:

In your .vimrc:

Install fzf vim plug

Running :PlugInstall in Vim will then copy FZF into the .fzf directory in your home folder and then run its post-install script to configure the native executable. FZF comes with basic Vim bindings out of the box, but I like to make a few changes:

In your .vimrc:

manage fzf vim tips

This maps the FZF search to Ctrl-F, and sets up hotkeys for opening splits in Vim similar to others I’m used to using. With only those few lines, searching for any file within the root directory becomes a breeze.

install manage fzf

Zsh history search

When vim-plug installs FZF, it also makes it available for use on your PATH as well. With a few entries in Zsh’s config, we can tie command history search into FZF:

In your .zshrc:

zsh history search

This sets up Zsh’s history search on Ctrl-R and then runs the FZF zshell script to configure FZF for it.

zsh history search gif

Customize FZF - ignoring specific directories

Now that we have our fuzzy find in place, there’s a good chance we’ll want to exclude certain entries from the results. Library dependencies, the .git directory, and others can be easily left out by setting the FZF_DEFAULT_COMMAND environment variable:

In your .zshrc:

fzf ignore directories

Add any other directories you want ignored with -o -name directory_name -prune.

Conclusion

Simple tools can make all the difference in being productive and covering ground quickly. I’ve found FZF to be a huge asset towards that goal, and it’s worth the investment to get a handle on it.


Enjoyed this post?

Other related posts

See all the ways we can help you grow through design, development, marketing, and more.

View All

Listen and learn from anywhere

A podcast about the craft of creating software and effective development teams.

iTunes
Spotify
Google Play
No items found.

The Manifest

Receive the latest articles, resources, events, and more!

Thanks for signing up!
Oops! Something went wrong while submitting the form.