Building Ogre projects from Vim

Jun 25, 2011

I use Visual Studio to compile and debug my Ogre project since the precompiled headers option gives me a significantly faster build (I’m awake that even GCChas support for precompiled headers now, but the first ten search results for the same in Google didn’t look very promising, so I didn’t bother to pursue it further). However, I use Vim almost exclusively for all my development, whether it be at the office or for my side-projects, so I found myself typing a lot of “w"s, “/“s and “dd"s while working on my project in Visual Studio. Looking for ways of emulating vim’s behavior inside VS yielded only one good result, ViEmu, which is unfortunately a commercial project. Plus, while VS’s indexer might be adequate, I missed ctags.

So, I looked for ways of efficiently doing all of my coding from Vim, and here’s the solution I rolled out: 1. Created separate tags files for the OgreMain directory and for my project’s directory using exuberant-ctags 2. Installed the FindFileplugin and put the following in my vimrc:

nmap <C-f> :FindFile<CR>
let g:FindFileIgnore=['*.obj','*.exe','*.ipch','*/Debug/*','*/Release']
  1. Added the following function in my vimrc:
function! LoadOgre()
    FC . ; The solution dir
    FC ..\..\OgreMain ; My VS solution is located in
                      ; Ogre/Projects/MySolution,
                      ; so this is Ogre's OgreMain dir
    set tags=tags,..\..\OgreMain\tags ; Take both tags files
                                      ; This is necessary so that vim recognizes lines in the
                                      ; build output that denote errors encountered during
                                      ; compilation
    set errorformat= %#%f(%l\,%c): %m ; this is what gets called when :make is invoked
                                      ; inside vim. By default, it's mapped to "make"
    set makeprg=msbuild /nologo /v:q
  1. I’ve also modified my project’s .vcxproj file and added <GenerateFullPaths>True</GenerateFullPaths> to the "Globals" PropertyGroup. This piece of info was obtained from this question on StackOverflow. Note that I haven’t explored how Vim’s makeprg handles different build configurations (Debug/Release etc.) yet since I’m only working on the Debug build at the moment, but it’s something I’ll have to figure out in the future, and I’ll post it here whenever I do so.

Now whenever I want to work on my project, I just have to

  1. Start the Visual Studio Command Prompt in my VS solution’s directory
  2. Start gvim and execute :call LoadOgre()
  3. Profit. I can run :FF<CR> to find files from either my project or Ogre’s source code, jump around using C-] and C-o (I have C-t mapped to :tabnew), run :make to compile my project, and use the quickfix window or :cn and :cp to jump to errors/warnings.