ramar.work

Vim Trickery

I love Vim, but admittedly, it’s not a batteries included IDE. Depending on your point of view, this is a plus or a minus. With some ingenuity, Vim can be made to act like just about any other IDE worth its salt.

A few years ago, I ran into this problem with Vim, but stumbled across Aric Blumer’s Project plugin. It worked well, but there were a few issues I encountered:

Recreating directories is a time-consuming process To generate a list, you must type ‘/C’ and specify a directory name and any files to exclude. (I got tired of this by the third time.)

Development has most probably stalled. The last version of this plugin was from October 2006 I always have to reinstall this plugin to Vim’s setup directory on whatever system I’m working on. However, I still really like using this plugin. It is intuitive and robust. Crashes and lockups are rare. While the ‘\c’ command (or ‘\C’ command for directories) can be slow with a large amount of files, it is extremely convenient when the top level directory changes. And once it’s installed, it’s finished. I don’t have to maintain anything or worry about performance suffering just to update a few files. File system watchers seem to have these sorts of issues all the time. It may not be the software, but I just don’t have time to debug issues like this in the middle of projects.

I’ve come up with some workarounds for the Project plugin. I use a script called ‘stree’ to quickly generate a list of files in a directory. (Please see ??? for more information.) It is nothing special. It runs a quick find on the directory you want to index, sorts it as best as it can by directories and files, and creates a file structured to fit with Aric’s plugin.

Problem solved, right? Not exactly. While fine for personal projects and slow computers. Building the index once can take a while on some systems, especially when running on an emulator such as Cygwin since Windows has no fork() call. so having a persistent file isn’t so bad.) It’s not great when trying to collaborate with others. Not everyone uses vim, and some places don’t even have source control handy. So we can work around this by creating a temporary file with the same information.

HASH="/tmp/`pwd | md5sum | sed 's/  -//'`"
[ ! -f $HASH ] && $HOME/prj/te-ide/tools/stree.sh -a $HASH
vim -c "Project $HASH"

Surely it isn’t the most well structured script. But this is perfect to mash into your .bashrc. I called it miv(). If you want to use it yourself, wrap it in a function and call it a day.

function miv() {
   HASH="/tmp/`pwd | md5sum | sed 's/  -//'`"
   [ ! -f $HASH ] && $HOME/prj/te-ide/tools/stree.sh -a $HASH
   vim -c "Project $HASH"
}