Are you pressing the up and down arrows of your keyboard while looking for a command you previously run in the shell? Then you probably know how many keystrokes you have to press to find what you are looking for. Stop digging holes on your keys! In this post we are going to install a nice tool called
fzf and we are going use it to speed up many common command-line operations.
fzf is a general purpose interactive command line fuzzy finder, used to filter large set of data in the shell. It basically allows to search for something without providing a 100% match. For example, if we are looking for files with the word
core in their name, a fuzzy finder will match all files including the word
core, but also files like
cat-on-tree, as the letters of the word
core are included in the proper order (searching for an exact match is just an extra character, we’ll see that later in this post).
Let’s start with the installation for macOS, for other platforms you can find detailed instructions here. We are going to use Homebrew:
brew install fzf
Then you need to run the installer using the following command:
This command will also ask you to enable
fzf autocompletion and keybindings, and to update your shell configuration files (it basically adds a line in your
Good, now it’s time to use our new superpowers.
You are looking for a command you typed time ago in your shell. You can press the
top-arrow multiple times, going through all commands you executed between the command you are looking for and the last, but that’s terribly slow. Or you can use
ctrl+r, which now presents a totally different output.
You can type for example
fzf will filter the results showing only the command with the word
You can move up and down between
fzf results, using the
down-arrow key, or even better using
ctrl+k to move up and down without leaving the comfort of the home row.
After finding your match you can press
ENTER to close
fzf and move the command inline, and
ENTER again to run the command.
Suppose you are looking for a file or a directory in the current folder or its child. Most shells have an autocomplete mechanism that allows you to press
TAB to automatically complete a filename or a filepath, but that requires you to write the exact filename or filepath from the beginning.
fzf you can press
ctrl+t to open the fuzzy finder, getting the list of all files available in the current directory and its child folders.
You can then filter as you do with commands and then press
ENTER to confirm your selection.
Some commands like
rm allows for a list of files to be provided as arguments, for example
rm file1 file2 deletes both files.
fzf comes to help also with this, as you can select multiple files from its prompt.
First of all type
rm, then press
ctrl+t to call
fzf. Then move with the arrows on one of the files you want to delete and press
TAB to select it. A little
> appears on the left of that file. Don’t press
ENTER yet, resume your search and look for another file, press
TAB when you find it. When you are done press
ENTER and both filenames will be displayed inline after
rm, ready to be deleted.
fzf is smart enough to provide useful completions to some popular commands. For example, type
cd and then the completion trigger sequence (default
**), then press
fzf will show you only the available directories to complete that command.
This will work also with
vim, if you type
vim ** and press
TAB, and many other commands.
You can view some other supported commands here, like
export. The one I personally use the most (except
vim) is for sure
ssh ** then
TAB, to autocomplete using my
fzf starts by default in Extended mode, this means we can use some tricks to get better results from our fuzzy search. Let’s see some examples:
!in front of your search (works with this others matchers too).
fzf is an incredibly useful everyday companion that you will miss whenever it’s not available. For now we only touched the basics, but you can do many other things with it, like the integration with a text editor for a super quick file search (vim support is well supported). Try it, you won’t be disappointed.