tags:

views:

94

answers:

2

Say, I have files foo.js and bar.css in my project. There is a ":find" command in vim, which find files, matching string. But this command, alas, has some limitations. For example, if I launch this way - "vim", or even this way - "vim ." - there's nothing to be find in js subdirectory. But if I launch vim this way - "vim js/any_file_other_than_foo.js", then calling ":find foo.js" works pretty well.

Since it is not intuitive (i'm working in the same directory, "pwd" returns the same path), my first question is - can anybody explain how to circumvent this issue? And, even broader, is there any way to type something like find foo - and open first file, which name matches pattern foo.

thanks in advance.

+3  A: 

You could try

:e[dit] **/*foo* and then press 'tab' to move to the first match.

the ** is a directory globbing pattern, while * is character matching.

If you were so inclined, you could write a simple fuzzy finder command, for more information you can check out the vim tips wiki: http://vim.wikia.com/wiki/Find_files_in_subdirectories

okay zed
okay zed, actually, it's not that simple. calling :e with wildcard will open all matches.
shabunc
I should have been more clear that pressing 'tab' will allow you to open only the first match.
okay zed
+1  A: 

A nice plugin that accomplishes a similar effect is Command-T.

The Command-T plug-in provides an extremely fast, intuitive mechanism for opening files with a minimal number of keystrokes. It's named "Command-T" because it is inspired by the "Go to File" window bound to Command-T in TextMate.

Files are selected by typing characters that appear in their paths, and are ordered by an algorithm which knows that characters that appear in certain locations (for example, immediately after a path separator) should be given more weight.should be given more weight.

Here is a screencast of Command-T in action.

Peter Rincker
it's a pity that such an awesome plug-in demands vim, compiled with ruby
shabunc