tags:

views:

118

answers:

3

What's the simplest way to "jump to a file somewhere in my source tree by name"? For example, if I'm working with "libfoo" that contains libfoo/foo/foo.py, I'd like to be able to jump to foo.py from anywhere within libfoo/**[0].

Possibly some way to do this with a tags file?

[0]: that is, libfoo/ and its subdirectories.

+2  A: 

check out command-t, FuzzyFinder, or FuzzyFinder_Textmate

Personally, I find command-t has the best UI, but FuF_Textmate is best for quickly getting to the right place in very large projects (which is why I use it after trying all 3)

Note that fuzzyfinder_textmate is unmaintained by its origional author, so you may have to poke around the gh network tab to find who has the most up to date branch. also note it is a bit of a pain to install.

Matt Briggs
I use FuzzyFinder_Textmate already for its tag jumping… But it's a bit annoying to use `file` because, if I'm in `libfoo/bar/baz/`, then I've got to type `\f../../../**/foo.py`.
David Wolever
Possibly there is some way to set it up so that it will default to using some directory as the root?
David Wolever
as far as i know, fuzzyfinder_textmate only does file names, and will always start in the place that you opened vim (which can actually be a pain sometimes). maybe you are using fuzzyfinder?
Matt Briggs
Err, yea — maybe I am just using FuzzyFinder.
David Wolever
the main difference between the two is for fuf, you have to walk through the whole path (i.e. l/f/fpy) with fuf_tm, it will just match by file name instead of complete path until you start using /s. so fpy will match it, but if that is too general you could do foo/fpy to narrow your search down
Matt Briggs
+5  A: 

Add ** is to you comma-separated vim path variable (not system path) and if you're in some parent dir of the project use:

:find foo.py
Ry4an
voted you up cause find is definitely simpler then installing and configuring a plugin.
Matt Briggs
Hrm, that doesn't seem to do what I want… If my CWD is `libfoo/`, `find foo.py` doesn't work. Possibly `:find` isn't recursive?
David Wolever
What does :set path tell you? Mine is `path=.,**,,`, which I think is the default. It definitely recurses for me. :find password in / find /etc/passwd.
Ry4an
Indeed, looks like `set path=.,**,,` is in my ~/.vimrc, which I cribbed from somewhere 10 years ago. Add that and `:find` is recursive.
Ry4an
Ah, there's the problem: my `path` is missing `**`. Strange, though — I'm running a mostly stock 7.2, and if `**` is default, then I don't know why I wouldn't have it (mine is `.,/usr/include,,`).
David Wolever
Default *is* `".,/usr/include,,"` on unix, as stated on `:help path`
Drasill
I guess that's the trouble with bringing the same ,vimrc along for years -- you forget the defaults. Updated the answer.
Ry4an
+2  A: 

You can use Vim's tab completion of filenames in conjuction with the ** recursive directory expansion.

e.g. type: :e libfoo/**/foo.py and hit TAB. This will search down from the libfoo directory to find a file that matches. If there is more than one match you can cycle through them with the TAB key. When you find the one you want press enter to complete the command and edit the file.

For more about the ** matching do :h starstar. It requires a version of Vim compiled with the +path_extra option.

If you have already edited the file once you can also search the buffers for partial name matches with the :b name command. e.g. :b foo.py<TAB> will expand to a buffer name that has 'foo.py' anywhere in it. N.B. it matches the entire path, so :b foo<TAB> would match all buffers with files from the libfoo directory.

Dave Kirby