The .Files

FZF as Vim package

As a Neovim user, I’ve been following the development of v0.5 with great interest. Native LSP and Treesitter look like great solutions to problems users clearly have. I’ve been slowly weaning myself off of coc.nvim in preparation for when all of this hits stable.

Admittedly, coc.nvim is a great plugin/ecosystem, and works great. Unfortunately, it’s a bunch of heavy js blobs that depend on both npm and yarn, which I’ve been tolerating for the sake of coc’s features.

Speaking of features, in the past I’ve relied rather heavily on coc-lists as a fuzzy finder, and coc-explorer for those hard to reach files.

I’ve (re)replaced coc-explored with Defx and decided it was time to bring FZF back into my vim config, so off to its repo I went, to check back on the docs.

I’ve always thought the instructions to use FZF as a vim plugin were a bit unclear and, as I discovered after a lengthy chat in #neovim, they actually are. Nonetheless, I remembered using it without much hassle before.

As a vim-plug user, my proposed solution had been to add Plug /usr/bin/fzf to the relevant part of my init.vim, but in the interests of going native as much as possible, I’ve been giving the packages system a try.

The way to get native packages working is to create a couple of folders somewhere in the runtimepath and just clone plugin repos in there. Some people prefer using git submodules but I’m not entirely clear on the benefits of this over cloning.
I keep my plugins in $XDG_DATA_HOME/nvim/site/pack/bundle placing the ones I always need loaded in the start folder, and the more specific ones in the opt folder for lazy loading. The latter require adding packadd! plugin-folder-name to init.vim.

This brings us back to the topic of FZF’s docs. Having FZF installed through a system-wide package manager gets us halfway there, but the docs state we should have both the entire program and the vim plugin in our plugins directory… wat.

As it turns out, FZF proper already comes with a wrapper that enables us to use it with vim (very confusingly called fzf.vim), but all of the premade functions most of us are used to (such as :Buffers, :Files, etc), are only available through the fzf.vim plugin. While this is more or less explained somewhere in the docs, the recommended solution of managing the FZF application itself through vim (thus having it installed twice) is bullshit and nonsense and just plain WRONG.

What should be done is use find (or fd or locate or whatever) to find out where this wrapper is installed and add that location to our runtimepath.
locate fzf threw a bunch of directories at me, the most interesting one being /usr/share/vim/vimfiles which is where the wrapper is in my system. The actual path is somewhat longer but this is the part that’s of relevance.
So now it’s possible to just clone the one repo and add a line to init.vim

TL;DR

  1. Install FZF through your system’s package manager
  2. Clone the plugin repo to the runtimepath. For Neovim, it looks like this:
$ mkdir -p $XDG_DATA_HOME/nvim/site/pack/bundle/opt
$ cd $XDG_DATA_HOME/nvim/site/pack/bundle/opt
$ git clone https://github.com/junegunn/fzf.vim
  1. Find the relevant file
  2. Add line to init.vim like so:
set runtimepath+=/usr/share/vim/vimfiles/
packadd! fzf.vim
...
  1. ???
  2. Profit!

The wrapper itself is inside a folder called plugin but if you add that to the route, then the file won’t be loaded. Go figure.

Epilogue

I couldn’t find any sign whatsoever of any of this ever being explained or talked about in either FZF repo. What little is there either doesn’t work or just reiterates that you should just install everything twice. Whatever issues have been opened have either come and gone or received answers so terse they might as well have been SteveMail1


  1. https://stevemail.tumblr.com/ ↩︎