Sunday, December 30, 2007

File Associations and PATH with MacVim

UPDATE: The newest release of MacVim has a preference pane that lets you "Launch Vim processes in a login shell." If turned on, it should solve the PATH problem suffered by some Vim users.
If you use Vim for OS X or the nascent MacVim, you may have noticed that
  • your PATH is not set correctly (i.e., compilations fail) and
  • Vim is not associated with all of your text files (i.e., it doesn't show up in the "Open With" context menu)
A while ago, I realized that the gvim.app available for download from the OS X Vim site had the potential to solve both of these problems, and so I hacked it to produce:
  • gvim.app (for Vim for OS X) and
  • mvim.app (for MacVim; maybe unneeded if "Launch ... login shell" preference turned on)
To install one of these files, download the archive, unzip it, and move the application into your /Applications folder. If you start Vim from that application, it will open as usual but will have the PATH set as if you were in the Terminal (i.e., it executes a bash login before exec'ing Vim). You should also notice that the new launcher application shows up in your "Open With" menus. Finally, if you put the launcher in your Dock, you can use it to generate new Vim windows, even if Vim is already open.

2 comments:

Unknown said...

Thanks Ted,

Works a treat and makes a huge difference! This should be integrated into both vim for mac projects.

Ted Pavlic said...

Daniel -- Thanks for the comment.

The trick behind mvim.app is that it execs MacVim from a login shell, and so PATHs get set correctly.

I'm not sure it's a good idea to make this the default for MacVim.app. There are some who may want to set the PATH through purely OS X means (i.e., without messing with shell config files). Forcing MacVim.app to run a login shell would cause problems for those people.

So, I think having an mvim.app and a separate MacVim.app is a great compromise. Best of both worlds.

That being said, there probably is a way to merge mvim.app into the MacVim.app trunk as a side support application that is hidden from most users.