Brendan Dawes
The Art of Form and Code

Goodbye XCode, Hello Vim and OpenFrameworks

Since moving to Vim over a year ago for all my coding, using another code editor is always a chore. Such is the case using Xcode when working on OpenFrameworks projects. Luckily I can use Vim to work on OF projects after reading this great post from the OF forum about setting up Vim and OF.

Yet there was one piece of the puzzle missing. To trigger compiling the code with the make command you would normally have to be in the same directory as the Makefile, which OF conveniently makes when you first setup an OF project. The problem is all the code you work on resides one level down in the src directory. Running make from there will do nothing. Thankfully it can be rectified by adding this line to your .vimrc:

:let &makeprg = 'if [ -f Makefile ]; then make Release && make RunRelease; else make Release -C .. && make RunRelease -C ..; fi'

When you issue the :make command it will check to see if the Makefile is present in the current working directory and if not will go up a directory and look for it there. I originally tried this with just using RunRelease but I found it wasn't compiling the new code and was just running the existing binary. To fix this I'm calling make Release then make RunRelease which seems to work well.

You can also set this to be configured whenever you open any .cpp file, rather than have it as the default, which could cause problems with Processing files. Just change the previous line to read:

autocmd  BufRead,BufNewFile  *.cpp let &makeprg = 'if [ -f Makefile ]; then make Release && make RunRelease; else make Release -C .. && make RunRelease -C ..; fi'

Syntax Highlighting

You can add correct syntax highlighting for OpenFrameworks c++ files using this plugin.

Now when working on OF projects I can stay in Vim without having to use Xcode.