OSX has this great tool called Spotlight, which allows you to search and open files from a simple text box, launched by a simple keystroke. Achieving this functionality in Linux is easy with fzf, a fuzzy finder that can search for files in any directory. fzf is written in go, lightning fast, and apparently popular among vim users, since it can easily be integrated to plugins for various purposes.
If Spotlight behavior is to be replicated exactly, one would need to create a GUI textbox
that can pop-up on top of other windows. However, since I am comfortable with
the terminal in my setup which I can just summon with
F1, I would be just as
happy with short terminal command.
fzf’s default behavior is similar to that of Spotlight, which starts listing
matched files. In Spotlight, the best match appears at the top of the list, and
automatically opens the file with the corresponding default app. When run
in the terminal,
fzf directs the path string to stdout when enter is
pressed. We can replicate fzf behavior with the following one-liner
fzf | xargs xdg-open &
fzf comes up; after the selection is made, it terminates
and the output is piped as an argument to
xdg-open which opens
files with the default app. The
& just sends the job to the background,
leaving your terminal free to operate. However, running
fzf plainly does the
search in the current working directory. If you want to search in your home
folder, for instance, you can type
echo ~/`cd ~; fzf` | xargs xdg-open &
The whole echo thing is necessary, because I could not find a flag for fzf that let me input the search directory.
In your shell, you can assign this to a function with a short name, say
Then you just type
ff to open files easily.
Note: This might be even better than Spotlight, because I think Spotlight doesn’t have the fuzzy functionality. Not exactly sure since I don’t own a mac.