The difference is that
:find will actually search for a file by that name in the list of directories specified in
. (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
Finally, if you use a path relative to the current directory, one that will work with
:edit, it will also work with
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:
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:
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
- projectionist.vim: Understands your project's paths and sets
- Other language-specific plug-ins, such as vim-ruby for the Ruby language.