2

I've recently discovered the following to find files in Vim.

 :Explore **/[pattern]

Finding files is pretty important to me, and I can't believe I've done without it for 8 years. I can relate to what this gentleman has said: http://vim.wikia.com/wiki/Find_files_in_subdirectories

I see people searching for files in TextMate and have to hang my head in shame :(

So using the above I'm able to search for files, "in theory", but the output baffles me and often has files that do not match. I'll use a Rails example.

For example doing this:

Explore **/envir*

Yields this, which a bunch of extra weird files:

../
deploy/
environments/
initializers/
locales/
.DS_Store
application.rb
authorization_rules.rb
boot.rb
config.yml
database.yml
deploy.rb
development.sphinx.conf
environment.rb
production.sphinx.conf
routes.rb
sphinx.yml
staging.sphinx.conf
test.sphinx.conf

That is at least usable, I can scroll down to environment.rb and open it.

But say I want to find a list of all helpers. I would think that this:

Explore **/*help*

Would work, but no files are found.

Can someone illuminate me?

pixelearth
  • 13,674
  • 10
  • 62
  • 110

3 Answers3

3

Have you look at the Ctrl-P.vim plugin? https://github.com/kien/ctrlp.vim

This plugins finds files in a similar way to what you show.

Peter Stuifzand
  • 5,084
  • 1
  • 23
  • 28
  • 1
    +1 for CtrlP. What you see people using in TextMate is the command-t option. There's a Vim plugin called CommandT that does fuzzy file finding, but it's no longer maintained. CtrlP is the new hotness and is likely to make you happy. – Jim Stewart Jan 23 '13 at 23:53
3

No, :Ex[plore] **/foo* sucks.

The above mentioned CtrlP is a beauty (that I use extensively despite a few limitations) that allows you to find files in your project and other niceties. FuzzyFinder and Command-T are worthy alternatives, LustyExplorer as well and there are obviously many others.

But Vim is quite capable by himself. The wildmenu option is key, here. Just add these two lines to your ~/.vimrc:

set wildmenu           " see :h 'wildmenu'
set wildmode=list:full " see :h 'wildmode' for all the possible values

With the setting above, the following command shows you an accurate list of matches that you can navigate easily and relatively intuitively.

:e **/foo*<Tab>        " see :h starstar

If the "working directory" is set to your project directory, that command is sure to give you good results. It's not very sexy (I like it, though) but it's very effective and dependable. Of course, this method can be used with :sp, :vs or :tabe.

The :find command is even better and probably more suited to yor needs: it looks into the directories defined in the path option. :set path=/path/to/project at the beginning of your session and you can open any file in your project with:

:find foo<tab>         " see :h :find

Neat.

Another possibility is to use "args". You add all the files matching some pattern to your "argument list" and use buffer navigation commands:

:argadd ./**/*.js      " see :h arglist
:sb foo<tab>

But it can be a little messy.

Overall, there are many elegant ways to deal with file navigation in Vim (and I didn't even mention tags-based navigation!). Plugins may provide a nice unified UI to a number of navigation needs but they are not required for finding files efficiently. At all.

It is interesting to note that both TextMate's and Sublime Text's implementations of fuzzy search are actually limited to the current "project" which is not the case for those Vim plugins or for Vim's buit-in file handling.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • It seems like you need to type `:find ./**/foo` for recursive file names – Willem D'Haeseleer May 28 '14 at 17:27
  • @WillemD'haeseleer no, `:find` is recursive: `:find foo` will find any file starting with `foo` and `:find *foo` will find every file with `foo` somewhere in their name. – romainl May 28 '14 at 17:52
  • I'm using vim 7.4 and i'm getting a bell when I do `:find foo` and a match on `:find ./**/foo` , the file is 1 directory deep, what could I be doing wrong ? – Willem D'Haeseleer May 28 '14 at 18:09
  • @WillemD'haeseleer, sorry, that behavior depends on the value of the `path` option. I suggest `**`. – romainl May 28 '14 at 18:51
0

If all you want is simple :find type functionality but with partial file name matching with tab auto-completion, the find-complete plugin is good.

lomilomi26
  • 33
  • 3