Friday, October 24, 2008

file lookups

I've been hearing about this post from a TextMate guy (I'll call him TM1) finally coming home to Vim(hey, if you're gonna link to some other random editor, you GOTTA plug your own!). Good good. In fact, from any command line editor's point of view: amazing. Its funny though because THIS TextMate guy (call him TM2) got me to write up a plugin very similar to TM1s.

Before I go any further - just click on the 'this post' link above and watch the short movie the guy recorded. I'm lazy, I'm not going to make a video. Once you've watched the video you'll understand what we're talking about: an gosh-its-almost-like-its-an-IDE friendly way of finding files in your project.

Its the kind of thing that just has to be there for any programmer under 35 - we're just not going to fall in love with the :find and :grep and :vimgrep commands of the previous generation. Its just not easy enough. For some people the project plugin does the job. I admit, I kinda like it myself...but I always missed the easy file lookups you get in Eclipse, IntelliJ, etc etc etc. Being a Java guy mainly, I really love how easy Intellij makes it.

When TM2 expressed interested in making the final journey from emacs->textmate->vim, you better believe I was there to encourage him. When he complained that there just wasn't any good Command-T equivelant in Vim, you bet I looked around. I found the lookupfile plugin. At the time this was version 1.4 of the plugin - it was slow, it didn't do camel case searches (fuzzy finder doesn't do that either !?), you couldn't search inside files (ala grep).

I extended the plugin with my own version and tried to get TM2 to use it. Unfortunately my skillz aren't quite what they could be in vimscript. However I was able to get the following working (and hey, it still works!):
  • I implemented searching using the standard unixy textutils and findutils packages underneath (find, sed, grep, xargs, etc). The first search is still slow b/c it builds up the search terms, but then they stay subsequent searches are blindingly fast.
  • Compatibility with &path and &suffixesadd settings (the variables used by :find, :grep, etc). Basically you can setup &path/&suffixesadd and use :find, :grep, and your friendly lookupfile functions all interoperably. I setup mappings where I only searched files; or java, xml and properties files; or ruby and xml and yaml. Complete control over which directories you search under, as well as their extensions.
  • Support for case sensitive or non case sensitivity.
  • Camel Case search. Not only can you do 'c*frog' to find '' (or with case sensitivity 'C*Fro'), but you can do 'CFro' as well (a * is implied after each capital letter).
  • Grep search: same way of searching (nice filtering list) but search the file contents as well. If it worked better, I'd maybe win that $100 bounty :).
But I had a problem - those darned findutils and textutils I built everything on aren't standard on OSX and so my TM2 friend had no end of trouble. It just was buggy. I guess it still is, but...

since somone else has published their version, and I found it hella slow, I figure...hell, here's my effort as well. Maybe someone out there would like to pick up where I left off.

You can find the result of my efforts right over here. Now.To work.


awt said...
This comment has been removed by the author.
awt said...

God. I feel so guilty!