Skip to content

Instantly share code, notes, and snippets.

@ben-axnick
Last active February 11, 2016 22:20
Show Gist options
  • Save ben-axnick/61fdaaeb037cd3124b12 to your computer and use it in GitHub Desktop.
Save ben-axnick/61fdaaeb037cd3124b12 to your computer and use it in GitHub Desktop.
FZF

Vim Fuzzy finding with FZF

The Vim fuzzy finding landscape (as known by me)

There seem to be three main competitors here:

Command T

https://github.com/wincent/Command-T

First project I used.

Pro:

  • Works reasonably reliably

Con:

  • Requires compilation
  • Requires language support in Vim itself
  • Need to manaually regenerate, this can take a while

Ctrl-P

https://github.com/ctrlpvim/ctrlp.vim

Pro:

  • configurable ignore list
  • no compilation or language support required
  • reasonably speedy

Con:

  • bad matching algorithm

FZF

https://github.com/junegunn/fzf

Pro:

  • general "unixy" solution, can fuzzy find any list of strings
  • plugins for Vim and Tmux
  • will also fuzzy find files for you on the command line
  • matching performance as strong as Command T
  • file list not cached, no manual reload

Con:

  • some inital setup required, not as bad as command T

Installing FZF the easy way

OSX

brew install fzf

Linux

git clone https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

Uh okay what did that do

The install script

  • gets a binary version of fzf
  • symlinks the fzf binary where it's expected

It then optionally does all or none of:

  • adds the plugin to your ~/.vimrc
  • adds keybindings for your shell (by adding a line to ~/.foorc)

I don't trust it to modify my dotfiles

You can compile a binary yourself and then use as much or as little of the magic as you desire. The Vim plugin is available separately as junegunn/fzf.vim. All the plugin cares about is that it has access to an executable fzf.

Better performance

Improving relevance

By default FZF matches returns all files in the directory tree. You can configure this behaviour by setting an environment variable. Since I already have ack setup with exlcude lists, I piggy back FZF on this.

With a modern version of ack, you can use:

export FZF_DEFAULT_COMMAND='ack -f'

It lists every file ack would have searched, if it was actually searching. Otherwise you're stuck with ack -g "".

You can also just pipe to fzf on stdin, and it will use that instead of executing a default command.

Saving keystrokes in vim

You should also bind map <leader>t :FZF<CR> in your ~/.vimrc while you're at it.

Other functionality

The two most useful things I find outside of vim are:

**<TAB>: fuzzy find on the command line

Ctrl-R: fuzzy find command history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment