TextMate “Go to file…” in VIM

May 11, 2010 4 Comments by Richard

Ahh, the great debate; which is the best text editor of them all?  I have used many of them, but I keep falling back to what for me is the classic one: VIM.

Second to VIM, however, I have always been very impressed with TextMate. There are features in TextMate that just make me happy.  My favorate is the “Go to file…” option (Command-T).  For those of you who aren’t familiar with it, when you press Command-T in TextMate a little popup window appears.  You type part of the filename that you are looking for and TextMate displays all files in your project that contain that string.

In my (not so) humble opinion, this has got to be about the best project management tool that has ever been conceived.  The problem, however, is that TextMate only works on Mac!  Granted, I have in recent years migrated to where I do most of my work on a Mac, but when I find myself working on Windows or Linux, I need my text editor!  That’s where VIM comes in.

VIM is about the most extensible editor I’ve ever used, and that is one thing I love about it.  Granted, there are disadvantages to it — the learning curve is heavy, for one.  But, once you figure out how to do things, it’s great.  However, it definitely is missing this “Go to file…” like ability.  This has bothered me for months, but only today have I finally found an adequate solution.

The Plugin is called Fuzzy Finder.  At first glance, it seems like it almost does what we need, but not quite.  However, combined with the Project plugin, you can come pretty darn close to TextMate’s “Go to file…” feature.

My purpose here isn’t to teach you how to use the project plugin, since there already exists plenty of documentation.   I will give you a few tips, however.

When you create an entry in your project list (\C), it asks you several questions:

  • “Enter the name of the Entry:” – This can be any name you wish
  • “Enter the Absolute Directory to Load:” – This should be the root path for your project
  • “Enter the CD parameter:” – This is the most useful option for us, but probably the least understood.
  • “Enter the File Filter: ” – I usually leave this blank, but you can use it to select which files to find

The trick that I have found is that if you specify the same path for the Absolute Directory and the CD parameter, when you open files in your project vim will use that as its CWD.

So now we have a project and we can browse the files.  We can also do fast searches in the project pane; simply use “/” to search for filenames.  However, this still isn’t quite what we wanted.

The next step is to install the Fuzzy Finder plugin. Fuzzy Finder is set up to let you quickly navigate a directory tree, but it also has some other unique features that make it ideal for what we want.  To open Fuzzy Finder to find a file, the command you want is “:FufFile”.  This will pull up the Fuzzy Finder mini-dialog.

However, this still isn’t quite what we want; it does let us navigate quickly with filters, but we want to quickly search through all files in the directory!  Well, as it turns out, FuzzyFinder supports wildcards; not just “*”, but also the less often seen “**”, which means “in all subdirectories”.  So, we can then do “:FufFile **/” to tell it to start searching there.

Depending on the size of your directory, this can be a bit slow — it’s not perfect.  However, you’ll find that this way you can very quickly search through your files to open the one you want — almost the same way you would in TextMate.  Keep in mind that this relies on where our CWD is, so you can use VIM’s lcd command to move to the root of where you want to search.

Now, typing “:FufFile **/” all the time is a little cumbersome, so you may want to add a shortcut.  If you really want it to be just like textmate, you could probably set Meta-T to open it, but I prefer to leave that for MacVim which uses it to open tabs.  Instead, I use the following:

nmap <leader>ff :FufFile **/<CR>

In my configuration this means that I just have to type “\ff” to have Fuzzy Finder pop up so that I can quickly open the file I want.  I also map \fb to Fuzzy Finder’s buffer search to quickly switch to another file in the buffer (“nmap <leader>fb :FufBuffer<CR>”).

Anyway, I hope this helps someone!

2 Comments

  1. k9d
    7 years ago

    is there anything like this for jEdit?

  2. Dmytrii Nagirniak
    7 years ago

    Small but awesome tips. Thanks.

2 Trackbacks

  1. […] folks may suggest using Project plugin which allows to setup the global cwd for each project. But that’s too […]

  2. By VimでRailsにRide onしてみる | shinodogg.com on February 6, 2011 at 11:35 pm

    […]  TextMate “Go to file…” in VIM(http://colonelpanic.net/2010/05/textmate-go-to-file-in-vim/) […]

Post a Comment

Your email is never published or shared. Required fields are marked *