The difference is that :find
will actually search for a file by that name in the list of directories specified in 'path'
.
The default 'path'
contains .
(which is the path of the current file), then /usr/include
(on Unix platforms, like Linux and Mac OS) and then an "empty" entry, corresponding to the current directory.
Which means if you're editing src/main/main.c
and you use :find args.c
, Vim will first search for it in src/main/
, which makes the default useful when you open many files in the same directory.
You notice your file includes <stdio.h>
and you would like to open this header file, then :find stdio.h
will find that in the system include directory. (An especially useful shortcut to this one is gf
, which will :find
the file name under the cursor, also using 'path'
.)
Finally, if you use a path relative to the current directory, one that will work with :edit
, it will also work with :find
.
And the behavior of :find
can be easily customized, by changing 'path'
to a setting that's more appropriate for your filetype (programming language) and specific project, to make it really easy to navigate between related files and browse files in a runtime's standard library.
To give you some ideas of how powerful 'path'
can be, consider these settings:
:set path=.git/..;
This will traverse up the tree, trying to find a .git
directory, then use the parent of that directory. In other words, this simple expression will look for the root of your git checkout and allow you to use :find
to access paths relative to this directory.
Another powerful example is:
:set path=**
Which will traverse down the tree and allow you to open a file under any subdirectory in the tree. (Note that you should avoid this setting, it's preferable to have 'path'
set in a semantically appropriate way for your language and/or project, which allows you to quickly access included files following the same path search as the language.)
You might want to consider enhancing this experience with plug-ins, in which case some recommendations are:
- apathy.vim: Set
'path'
and friends for languages such as C, Python, JavaScript and Go.
- projectionist.vim: Understands your project's paths and sets
'path'
appropriately.
- Other language-specific plug-ins, such as vim-ruby for the Ruby language.