Edit in MacVim SourceTree Custom Action

I when making small changes to files, I tend to favor using MacVim instead of firing up my IDE. While I do a lot of git commands with the terminal, I still use SourceTree a fair bit. It’s terribly slow at times with large repos, and uses up a ton of memory. But when it comes to visualizing my diffs and staging chunks, I just find it easier than the terminal.

One of the cool features in SourceTree is custom actions. With them, you can right click a file and perform any pre-defined custom action on it. In my case, I have only one set up. Edit in MacVim

  • Open SourceTree, and go to preferences -> Custom Actions
  • Add a new custom action
  • Menu Caption: Edit in MacVim
  • Script to run: /usr/local/bin/mvim
  • Parameters: $FILE

It was while setting up a new computer that I learned something by mistake. If you launch MacVim from the mvim script (either mine, or the one in MacVim.app/Contents/bin) then automator services, and SourceTree will wait until MacVim closes before they consider the command complete.

This behavior can be nice some times. Why do you need SourceTree to update the git status when you’re currently editing the file. However, sometimes it’s a huge pain because you want to open two or three files. To get past this, you can launch MacVim with the open command instead.

As always, there is a however. SourceTree doesn’t launch the custom action using bash. So you need to put together a little script

Then set up a custom action in SourceTree using that script. This will make source tree run the script without waiting for MacVim to finish processing.

I’ve added two custom actions to SourceTree “Edit in MacVim (sync)” and “Edit in MacVim (async)” so that I always have both options

Leave a Reply

Your email address will not be published. Required fields are marked *