Vim documentation is the best point to start. :help findfile()
:
findfile({name}[, {path}[, {count}]]) *findfile()*
Just like |finddir()|, but find a file instead of a directory.
Uses 'suffixesadd'.
Example: >
:echo findfile("tags.vim", ".;")
Searches from the directory of the current file upwards until
it finds the file "tags.vim".
You can use Ctrl+] to navigate into links, such as |finddir()|
:
finddir({name}[, {path}[, {count}]]) *finddir()*
Find directory {name} in {path}. Supports both downwards and
upwards recursive directory searches. See |file-searching|
for the syntax of {path}.
Returns the path of the first found match. When the found
directory is below the current directory a relative path is
returned. Otherwise a full path is returned.
(...)
You can debug that call using this:
:echo findfile('.gitignore', system('git rev-parse --show-toplevel'), -1)
This will run the findfile()
and echo the result in the screen.
You can use q:
to edit the call and test again.
Edit
You could try to understand it better by using simple examples. For instance, try to search for a nonexistent file in the current direct, then create the file and repeat:
echo findfile('bla', .) " empty result, no file
!touch bla " create the file (this works in *nix systems)
echo findfile('bla', ".") " now it returns a non-empty result
You can check that you are in the directory you expect by using :pwd
and getcwd()
.