You can use the :find
command to locate a file by name and open it for editing.
:find
will search for the file in the directories listed in 'path'
, which by default includes the current directory. You can add more directories to 'path'
that you want to look up, and you can use wildcards, including **
to traverse multiple subdirectories.
In particular, to find files recursively under the current tree, you can use:
:set path+=**
NOTE: This can be very slow in trees with many subdirectories, so be careful with this setting. Prefer to specify narrower subsets of the tree, where to locate files you're searching for.
You can also take a look at :help file-searching
for more details on the kinds of expressions available to use in 'path'
.
Second, you can specify extensions to add to the file names, using the 'suffixesadd'
setting. For example, if you're working on a project using Python, HTML and JavaScript, you can use something like:
:set suffixesadd=.py,.html,.css,.js
Having both 'path'
and 'suffixesadd'
set, you can use a command such as :find ui
to open file static/javascript/frontend/ui.js
. Pretty neat, huh? Or :find model
to open src/db/model.py
.
Note you always need to specify the full name of the file (except for the path and the extension.) If you wanted something that would handle incomplete filenames only, then consider plug-ins such as ctrlp.vim or fzf.vim to extend Vim with support for fuzzy finders.
You also asked about ignoring backup files. When you're completing filenames (for example, using Tab after a :e
), you can ignore files matching certain patterns by adding them to the 'wildignore'
setting.
For example:
:set wildignore=*~,*.bak
This will skip backup files when completing filenames on a :e
command line.