I would like to share a quick tip which can highly improve your workflow (at least it did with mine). If you usually work with the command line, you might have experienced that it is sometimes difficult to remember where is a certain file located. You might have some idea of which directory it was it in, but you might not even remember exactly the file name. For sure, tools like
find can help you, but they are not as fast and convenient to do as one might like.
If you have ever felt like this, you need fzf.
As its Github page states, fzf is a general-purpose command-line fuzzy finder. This means that it can find strings in a glimpse, even if you do not write the string correctly. For example, I want to view a file with a name that is somehow similar to “GreatLinuxApplication.c”. Or was it “great_linux_application.c”? With
fzf, you do not need to worry, since if you write something at least similar to the real application name, it will find it for you.
fzf can be used in many ways, although three key tasks that I very easily incorporated into my workflow are:
fzfto navigate the command history (Ctrl+r).
fzfto search for files at uncertain locations (Ctrl+t).
vimto open new tabs.
Key bindings for 1 and 2 are provided by
fzf during installation (although they are optional). The following screenshots depict both methods.
With regard to vim integration, it does not come out of the box, but it is very easy to set up. You simply need to follow the instructions to install this plugin. Once installed, I added a key binding to launch
fzf from inside
noremap <C-f> :FZF <CR>
My workflow then becomes:
- Hit Ctrl+f to launch
fzfat. Then I write the name of the file that I want to work with, such a class name. For example, for opening FancyClass.cpp and FancyClass.h I would simply write “fancyclass”.
- I select all files that I want to open using Ctrl+TAB.
- I open each file in a different vim tab by hitting Ctrl+t. It is also possible to open them in window splits with Ctrl+x/Ctrl+v, but I prefer tabs in general.
That’s it! It has been possible to improve my workflow with very few requirements and a non-existing learning curve. This has value on its own, because although there are hundreds of useful tools out there, it is often difficult to pick them up and start using them off-the-shelf. Fortunately, in this case
fzf delivers quality without any hassle.
If you want to stay updated about useful tips like this, follow me on Twitter (once I create an account)!
PS: Thanks to Pablo Navais for showing me the path to fzf and other wonderful tools.