Ad blocker interference detected!
Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers
Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.
created 2006 · complexity basic · author gautamvsg · version 5.7
This tip is for loading project files that you know the names for, but do not remember their paths.
Usually when you are working on a project and you want to load a particular file that is somewhere deep in the directory hierarchy, you have to either find the file on the command line and then load it into vim, or use vim tab completion to navigate and load the file. You can use vim's "find" feature instead.
Make the following entry in you vimrc:
This will set your path variable to current directory (from which you launched vim) and to all directories under current directory recursively.
Now all you have to do is to open vim/gvim from the base directory of your project. Then if there is a file that you want to open but dont remember the path for it, do a
and it will open the file that you want.
- If you have multiple files with the same name, then you are in trouble. Find will not list them out (like cscope/ctags) before it opens the file. You may end up making edits in the wrong file. However, enabling wildmenu solves this by displaying the possible matches and allows you to choose which file you want to edit.
- The find does not take any wildcards. So you cannot afford to make spelling mistakes in the file names (esp. java names)
In spite of the caveats, finding in this manner is far faster than navigating through directories to look for files (esp. if you are a touch typist.)
- You can change your path variable anytime to change the find path.
- You can use
:findto open it in a split window.
- Coupled with cscope (see :help cscope) you editing code across files becomes very convenient.
Since v58 of netrw, there's
which brings up directory listings based on files matching the pattern. For example:
The cursor is left on the matching file so it can be brought up easily. To skip from one matching file to the next:
:Nexplore (or, if you have a mouse enabled: <s-down>) :Pexplore (or, if you have a mouse enabled: <s-up>)
See also qf.
There was a previous tip in the same thematics. See Open file under cursor.
Regarding the fact several files may match, you can have a look at the plugin SearchInRuntime I'm maintaining.
The commands defined don't have any problem with wildcards, they even support auto-completion. It does not provide a command to edit in the current buffer, but two commands to edit in a split (horizontally or vertically) window. If the file is already opened in a window, we jump to that window. Vim 7 is required. (Surely you mean "edit in the current window", not buffer.)
On Windows use,