FZF Usage Guide

I've been using FZF for a little while, but not very effectively. So thought I'd get down some usage guides to help me when I turn to it in future and get the muscle memory firing.

As ever, fzf --help is your friend. In Vim :help FZF.

From Terminal

Opening a file with fzf using bash expansion. Below will run fzf where you can type to find the target file, when you have the target file selected hit enter and it will be opened in Vim.

vim $(fzf)

You can also run fzf in a tmux pane.

vim $(fzf-tmux)

Open multiple files, tab to select.

vim $(fzf -m)

From Vim

I have the following in my .vimrc

let mapleader = "\<Space>"
nnoremap <leader>o :FZF -m<cr>
nnoremap <leader>r :FZF -m ~/home/tome/repos<cr>
nnoremap <leader>1 :FZF -m ../<cr>
nnoremap <leader>2 :FZF -m ../../<cr>
nnoremap <leader>3 :FZF -m ../../../<cr>

This means I can hit Space + o to find files in current directory, with multi select. Then Ctrl + t to open the selections in tabs or enter if only 1 file selected.

CtrlP allowed you to switch directory, this doesn't seem to be possible with FZF so the mappings with numbers allow me to open FZF in parent directories.

Sometimes I only need to search git repositories, hence r mapping above. In addition to this you can search git commits (once you have vim-fugitive installed) with :Commits. To run this in a new tab:

:tabnew | :Commits

In vim gt and Gt allow you to select next and previous tabs, you can also do 1gt , 2gt to move to a tab by order. This can get a bit cumbersome, FZF allows you to run a :Buffers command that will open up the fzf interface so you can quickly select a buffer to open, by the provided index or by typing.


For convenience I use the below mapping.

nnoremap <leader>b :Buffers<cr>

Want to switch color schemes in Vim


If you have the Silver Searcher installed ( sudo apt-get install silversearcher-ag on Ubuntu) you can run :Ag some_pattern to find files containing the pattern.

To search through lines in the current buffer use Lines which will allow you to find any line by typing text that is in that line.

Use :Locate to find files with specific extension ( at least that's how I started using this ), e.g. :Locate .md

If you use Vim you forget mappings occasionally ( hard to keep track when you get plugin bloat), well :Commands has got your back. It will show you all the available commands in Vim, including for plugins.

Below is from :help FZF with all Commands listed.

 Command          | List
  Files [PATH]    | Files (similar to  `:FZF` )
  GitFiles        | Git files
  Buffers         | Open buffers
  Colors          | Color schemes
  Ag [PATTERN]    | {ag}{5} search result (ALT-A to select all, ALT-D to deselect all)
  Lines           | Lines in loaded buffers
  BLines          | Lines in the current buffer
  Tags [QUERY]    | Tags in the project ( `ctags -R` )
  BTags [QUERY]   | Tags in the current buffer
  Marks           | Marks
  Windows         | Windows
  Locate PATTERN  |  `locate`  command output
  History         |  `v:oldfiles`  and open buffers
  History:        | Command history
  History/        | Search history
  Snippets        | Snippets ({UltiSnips}{6})
  Commits         | Git commits (requires {fugitive.vim}{7})
  BCommits        | Git commits for the current buffer
  Commands        | Commands
  Maps            | Normal mode mappings
  Helptags        | Help tags [1]

If you don't have this plugin, you need it!! It's excellent.