Vim Tips Wiki
(fix link for removed tip)
(Change <tt> to <code>, perhaps also minor tweak.)
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
|previous=1142
 
|previous=1142
 
|next=1147
 
|next=1147
|created=February 22, 2006
+
|created=2006
 
|complexity=basic
 
|complexity=basic
 
|author=gautamvsg
 
|author=gautamvsg
Line 38: Line 38:
 
'''Variations'''
 
'''Variations'''
 
* You can change your path variable anytime to change the find path.
 
* You can change your path variable anytime to change the find path.
* You can use <tt>:sfind</tt> instead of <tt>:find</tt> to open it in a split window.
+
* You can use <code>:sfind</code> instead of <code>:find</code> to open it in a split window.
 
* Coupled with cscope (see :help cscope) you editing code across files becomes very convenient.
 
* Coupled with cscope (see :help cscope) you editing code across files becomes very convenient.
   
Line 70: Line 70:
 
(Surely you mean "edit in the current window", not buffer.)
 
(Surely you mean "edit in the current window", not buffer.)
 
----
 
----
On Windows use, <tt>set path=.\**</tt>
+
On Windows use, <code>set path=.\**</code>
   
 
----
 
----

Revision as of 06:09, 13 July 2012

Tip 1146 Printable Monobook Previous Next

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:

set path=$PWD/**

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

:find <full-file-name-including-extension>

and it will open the file that you want.

Caveats

  • 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.
  • 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.)

Variations

  • You can change your path variable anytime to change the find path.
  • You can use :sfind instead of :find to open it in a split window.
  • Coupled with cscope (see :help cscope) you editing code across files becomes very convenient.

Comments

Since v58 of netrw, there's

:Explore **/pattern

which brings up directory listings based on files matching the pattern. For example:

:Explore **/*.txt

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, set path=.\**