TextMate and Quick Searches

Posted on March 19, 2007

I've been using TextMate since probably the first public version. At least my license dialog shows October 6th 2004, Serial Number #60. And, oh boy, I've been a happy user. I can't declare that this is the best editor out there, and I don't want to start another editor vs war. I've been using Vi(m)/emacs for such a long time that I can't even remember and I'm not going to give up on them just yet. But I can say that TextMate is definitely a unique piece of software that sets a high mark for other editors to follow.

I think the most innovative feature of this editor is the way it represents the document structure with scopes. Everything else is built around this structure: shortcuts, snippets, commands, code highlighting, etc. This very feature makes it so much easier to customize your editor, than anything I've seen so far. (Whatever I've tried I couldn't make mmm-mode package work for me).

Another thing that I'd love to have from any editor is a desktop integration. Don't get me wrong, I'm an avid terminal and CLI proponent, but I've access to the most powerful desktop out there and it would be sad if I can't enjoy it when I'm writing my documents. And TextMate allows me enjoying both of these worlds.

OK, enough of TextMate praises, there are still some areas where this editor needs some love. One of them is the search capability. The regular and incremental searches are fine, I'm talking about the Find in Project search. First of all, it's quite slow and it used to take a lot of your RAM. Second of all, I've found that in about 95% of all cases, I need to search in a particular directory of my project. So I did what everyone else does, I created my own command, which I am about to share with you.

Quick Search

This command uses grep utility to search in your documents. It's bound to ⌃⇧F keystroke and uses a selected text or prompts you for a query text. What makes it quite useful is that, if you have a project opened, you can select a directory in the project drawer and this command will limit the search only to this directory and all subdirectories. Also you can define the environment variable TM_QS_FILTER in your project settings with a value of a regular expression that selects all files and directories that you don't want to search in. For example, I'm using (tmp|log|rails)$ value for my Rails projects.

Enjoy.

Comments
  1. Todd WerthMarch 21, 2007 @ 03:28 PM

    I agree, TextMate is the bee knees. I find it interesting how many other editors are creating TextMate like features, many of them specifically saying they are copying TextMate. TextMate's developer(s) should be proud to have caused such a commotion.

    Nice command, I just tried it out and it works really well. Being able to do a quick search on the selected text is great, thanks.

  2. John WhitleyMay 29, 2007 @ 02:11 PM

    A note about quickSearch.tmCommand: you (or your readers ;-) might want to add the '-I' option to the grep call. That treats all files detected as binary as not matching. This avoids a lot of (time, memory, cpu) problems when searching in projects with binaries, without having to exclude all the binary file types manually.