Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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?

like image 404
Cory Klein Avatar asked May 05 '11 15:05

Cory Klein


People also ask

How to search for a path in Vim?

Vim offers several commands for searching for files by name: :find, :sfind, :tabfind on the command-line, several normal-mode commands like gf, and others. If you just enter :find filename , Vim will directly open the first file found in your 'path' matching "filename".

How to open another file in Vim split screen?

Suppose you have opened a file on Vim editor and you want to split it vertically. To achieve this: Enter command mode by pressing the ESC button. Press the keyboard combination Ctrl + w , followed by the letter 'v' .


1 Answers

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.

like image 168
Cory Klein Avatar answered Nov 15 '22 23:11

Cory Klein