to locate the file and then edit it. I was trying to find if there is some solution directly in Vim, and haven't found one. Closest were <tt>:find</tt> and <tt>:globpath()</tt>. <tt>:find</tt> works nearly as I need, but unfortunatelly it opens the first file of a given name without telling me that there are more. For <tt>globpath()</tt> I was unable to make it work with the '**' construction, so that it would look into all subdirectories under current directory.

+

to locate the file and then edit it. I was trying to find if there is some solution directly in Vim, and haven't found one. Closest were <code>:find</code> and <code>:globpath()</code>. <code>:find</code> works nearly as I need, but unfortunatelly it opens the first file of a given name without telling me that there are more. For <code>globpath()</code> I was unable to make it work with the '**' construction, so that it would look into all subdirectories under current directory.

So I wrote this small function. You can use it like this:

So I wrote this small function. You can use it like this:

Line 87:

Line 87:

The only caveat (and it's a major one) is that it's very slow.

The only caveat (and it's a major one) is that it's very slow.

−

There's also the <tt>:Explore **/[pattern]</tt> command, available via netrw.vim. Example:

+

There's also the <code>:Explore **/[pattern]</code> command, available via netrw.vim. Example:

<pre>

<pre>

:Explore **/*.vim

:Explore **/*.vim

Line 95:

Line 95:

----

----

−

When I try the <tt>:Explore</tt> command it gives error: <tt>E77: Too many file names</tt>

+

When I try the <code>:Explore</code> command it gives error: <code>E77: Too many file names</code>

Adding a quit button is not a bad idea. Vim internal pager has quit bound to 'q' (see {{help|more-prompt}}), but this will stop my original script. I tried to use try-catch block around and it seems to work.

Adding a quit button is not a bad idea. Vim internal pager has quit bound to 'q' (see {{help|more-prompt}}), but this will stop my original script. I tried to use try-catch block around and it seems to work.

Line 156:

Line 156:

well, is on the shell $PROJECTDIR defined the include recursive all directories.

well, is on the shell $PROJECTDIR defined the include recursive all directories.

−

with <tt>:find foo.cpp</tt> it's open the file on Vim.

+

with <code>:find foo.cpp</code> it's open the file on Vim.

----

----

Line 236:

Line 236:

------

------

This is the slightly modified version of the script so it accepts an optional (second) argument.

This is the slightly modified version of the script so it accepts an optional (second) argument.

−

If given it represents a path to be used in a search. The result of the search is redirected to a quickfix window.<br> The quickfix window gets focus after the search is done.

+

If given it represents a path to be used in a search. The result of the search is redirected to a quickfix window. The quickfix window gets focus after the search is done.

I'm working with big, nested workspaces and often I don't remember the exact path to the file, only its filename or part of the filename. If I know some of the text in the file, I could always recursively use 'vimgrep', but for searching on filenames alone I have been using:

:!find . -name ...

to locate the file and then edit it. I was trying to find if there is some solution directly in Vim, and haven't found one. Closest were :find and :globpath(). :find works nearly as I need, but unfortunatelly it opens the first file of a given name without telling me that there are more. For globpath() I was unable to make it work with the '**' construction, so that it would look into all subdirectories under current directory.

Comments

You can load an arbitrary list of files with :args <pattern>, for instance:

Open all .c or .h files in the directory (and it's subdirectories) two directories up from the current directory:

args ../../**/*.[ch]

The only caveat (and it's a major one) is that it's very slow.

There's also the :Explore **/[pattern] command, available via netrw.vim. Example:

:Explore **/*.vim

This command will show the current match number out of the total quantity of matches in the status line, and one may move forwards and backwards in the matching files list. Hitting the <CR> on a matching file opens the file, of course.

When I try the :Explore command it gives error: E77: Too many file names

Adding a quit button is not a bad idea. Vim internal pager has quit bound to 'q' (see :help more-prompt), but this will stop my original script. I tried to use try-catch block around and it seems to work.

if exists("$PROJECTDIR")
set path=$PROJECTDIR/**
set tags=$PROJECTDIR/tags
endif

well, is on the shell $PROJECTDIR defined the include recursive all directories.

with :find foo.cpp it's open the file on Vim.

Yes, I have been using construct very similar to yours, the trouble was that :find opens first file of a given name it finds, without telling you that there are other two.

The other thing, :find also does not like wildcard characters, they are expanded before the :find is executed. I would like to be able to use ':find blah*.c'. Or maybe I just don't know how to use :find properly ? :)

The tags mechanism is how I jump around files. The Exuberant Ctags tool allows you to tag the files themselves.

This is the slightly modified version of the script so it accepts an optional (second) argument.
If given it represents a path to be used in a search. The result of the search is redirected to a quickfix window. The quickfix window gets focus after the search is done.

One more slight modification. If only one file is found, the script directly above this comment will not open anything. And since there's no need to open the quickfix list for one file, it just opens it directly (like find).