Published: 01.05.2021 | Edited: 09.05.2021 | Tags: 100daystooffload,vim
Smart global search for vim and fzf
In the previous post I have outlined that there are some benefits to having a
fzf command search everywhere in the home folder, instead of just current working directory. Following the setup there enables for yanking and pasting lines from the files stored in distant places (in the terms of traversal depth). But there is a significant cost to this, as now it is even harder to access relevant files stored near each other as the actual path is cluttering the view and has to be traversed generally and output lists all the files in the home folder, even including hidden files (files starting with a dot, dotfiles). Also, with very high files count, the speed decrease could start becoming a factor too. This is a very unfortunate scenario, but it can be improved upon significantly.
Ignoring hidden files with fzf
It is of course possible to exclude hidden files from the find command output. At the same time however, there are search commands that do that automatically, without too much additional hassle, for instance fd. Replacing our three lines to the point fzf ignores hidden files can be in
.zshrc like so:
export FZF_DEFAULT_COMMAND="fd --type f" export FZF_CTRL_T_COMMAND="fd --type f" export FZF_ALT_C_COMMAND="fd --type f"
Making sure we use
fd instead of
find in our fzf searches we also got another benefit for free.
Excluding ignored files
Apart from ignoring hidden files,
fd also respect
.gitignore files. So as a side effect of excluding hidden files from the output we also exclude ignored files at the same time. This is fortunate as is greatly reduces the clutter from the folders like
node_modules, as they are commonly ignored in the repositories.
I know some other programming languages apart from node like go or rust all can create vast folder structures in the home folder and we generally have no need to edit or view any of the files inside them manually, as they contain code for packages downloaded from the Internet.
fd respects the
.gitinore only when used in an actual git repository. I am not sure why exactly is it so at this point, but the problem can still be solved elegantly. Instructing
fd to ignore specific folders outside of the git repository, just mention them in the
Common folders to exclude
So, if you for example use
yay command to access software packages from the AUR, you probably have
~/go/ folder. A similar story goes for
paru, a sucessor/spin-off to
yay, but this time you could find yourself wanting to exclude results of
~/rust/ folder. Now place something relevant in your home folder's
.fdignore file has the same syntax as
.gitignore, meaning that the trailing slash denotes a folder. The leading slash denotes that only the entry placed at the top level should be ignored. In this case it's a folder and another one in the same location as a
.fdignore file - in the home folder. This is useful when there are folders with the same name deeper in the tree, that we do not want to ignore, for instance
~/work/go/ would not be ignored, but
This is a 52th post of #100daystooffload.