Question

How do you have vim find or search for a file in the path when opening a split?

In vim, I can find a file and open it in a new tab using :tabfind, and I can open a file I know the location of in a new split using :split or :vsplit. However, I would like vim to find files for me in my path when running the :split or :vsplit commands. For example, say in my current directory, I have these files (all of which are in my path):

./ReallyLongFileName1.txt
./fooDir/ReallyLongFileName2.txt
./barDir/bazDir/ReallyLongFileName3.txt

I would like to type the following command in vim:

:vsplit R<Tab>

And have vim search in my path for all files that match that expression, and fill the rest of the line with

:vsplit ReallyLongFileName

This works perfectly with :find or :tabfind, but it doesn't work when splitting. Is there a command that does this that I just don't know about, or is there some way to add this functionality to the :split and :vsplit commands?

 21  5239  21
1 Jan 1970

Solution

 24

As romainl said, :sf is the command that performs this action. There is no vertical split find, although you can do the same thing with the slightly longer command :vert sf.

2011-05-05

Solution

 8

Typing :split | :find<space>R (meaning "open a split then find..." seems to do the trick. Same thing with :vsplit.

Making it a custom function and calling it with a nnoremap would make it even better.

Edit:

I didn't know about :find and :tabfind so I looked them up in Vim's help and I found :sfind which does exactly one of the things you want. Unfortunately I don't see a :vfind or :vsfind.

Look it up: :help sfind.

2011-05-05