Archive for April, 2007

h1

V: find and edit files quickly via your commandline

April 23, 2007

I’m working on a project with a lot of files. Most of the time, I know exactly which file I want to edit. However, because everything is nicely organized in directories and packages, it’s very tedious to keep typing a long file-path.

I created a small tool which recursively searches for the (partial) filename you provide in the current directory. If it finds only one match, it will launch vim for that file. If it finds more matches, it will show you a list of files to choose from. It will remember your choice, and assign a weight to that file, so that it will bubble to the top of the list next time.

Currently the weight is assigned to the relative filepath. This means that you can easily switch to another branch of your project if it has the same structure. It also means that you always have to run the program from the root of your project.

As a small bonus I added a feature where you can specify the command to run. By default it is vim, but if you provide a different command as the second argument, it will launch that command. For example, you can run it as “v myfile less”, which will open the selected file in less instead of vim.

I hope you enjoy it, let me know if you do. Here’s the link: v.rb. Save the file somewhere in your path.