Search code examples
vimvineovim

How to search hidden directories/files with path=.,** and :find?


I have been using junegunn/fzf.vim to quickly find (hidden and non-hidden) files in vim. I just found out that it's also possible to set

path=.,**

and use :find some-file to achieve pretty much the same except fuzzy-searching. Since I rarely use fuzzy-searching and prefer to use as little plugins as possible (it's still a ton though), I am thinking about abonding fzf.vim and completely switching to the path/:find-approach.

That said, there is one important feature missing for me here. As far as I can tell, path doesn't include hidden directories. For example, given the following directory structure

~/testdir
❯ tree -a
.
|-- .hidden-folder
|   |-- some-hidden-file
|   `-- some1-hidden
|       `-- some2-hidden
|           `-- deeply-hidden-file
|-- some-file
`-- some-folder
    `-- some1
        `-- some2
            `-- deep-file

6 directories, 4 files

and opening vim some-file, :find deeply-hidden does not find the file. I assume this is because it is inside a .hidden-folder since :find deep-file is found.

Is there some way I can set ** to include hidden folders as well? Maybe it's also possible to tell vim to use a specific command for searching, so I can configure it to include hidden files/folders.


Solution

  • The built-in routine used for searching files uses a "depth-first search" algorithm which makes it quite inefficient in many scenarios. set path=.,** may thus be a bit excessive as it will force Vim to look into every subdirectory before switching to the next directory. It may work in some cases (as emphasized in my answer you linked to) but you should know that 'path' is intended as a list of specific directories and having ** in there kind of defeats its point. The "right" way to make :find go through hidden directories is to add them to 'path':

    set path+=.some_dir
    set path+=.some_other_dir
    

    While it would certainly be an improvement over the current situation, replacing the current algorithm with a "better" one (say iterative deepening depth-first search) can only be done in Vim's C source as Vim doesn't expose a 'filesearchprg' option or similar, unfortunately.