Projects with Vim using projects.vim 02.09.2009

I've been using NERD tree in Vim for a while now, liking the way it easily presents the files I'm working on in a tree format. Unfortunately, many times, I don't need all the files that it lists. And other times, the files I do need are scattered across disparate locations.

So I went looking for another solution, and think I've found it. Project.vim.

At its root, the plugin takes advantage of Vim foldings to show and hide groups of directories and files. Here's what it looks like in action:

Project.vim in action

The file listing on the left may look a little arcane, but is actually very easy to create. It's possible to manually create it, but I find it typically easier to using one of Project.vim's commands: \C

Given these files:

Files in Finder

I go into a Vim window, and type :Project. This will initially open up an empty project window. I already have one in there, but no matter. A single Project file supports multiple groupings.

Project window

Type \C in the Project window, and a prompt will display.

Project window

Above, I've titled the project "Django Trunk". It will then ask you for the path to the root directory of the project:

Project window

Eventually, it will ask you for a file filter. The format is a standard file glob syntax.

Project window

Let it parse through the directories and eventually you'll end up with:

Project window

Now you can use the standard vim folding commands to navigate. Or you can use arrow keys, / searching, or any manner. At its core, the Project window is a standard Vim buffer. The Enter key toggles foldings open and close. Pressing Enter on a file opens it in the most recently used window.

But what happens if there's a file or folder you need that's not in the project root? No worry, just add it in:

Project window

As usual, :help Project will give more documentation. But in brief, the basic syntax of the Project is:

Project_Name=Path_to_root_folder filter="Glob_filter" { }

The syntax is nestable, meaning that inside the curly braces, you can have another group defined using the same syntax.

The values also inherit from parent to child -- meaning if the path of a child isn't defined, it will take the path from the parent.

All in all, I find this to be more useful to me than NERD Tree. Once I set up my project, I see only the files I want to see without having to expand a massive tree.