Compile any project on windows from vim directly

vim is a powerful editor, and can compile many standard ways, thanks to the vanilla capabilities, and plugins. But sometimes, projects have in-house build systems. Here too, the flexibility of vim makes it able to accommodate for that in just three simple steps: symlink nmake.exe, write a Makefile.win that bridges, and a .local.vimrc to save the settings per project. Here are detailed instructions for how to configure this.

symlink to nmake.exe

Setting a path in vimrc is painful when it contain spaces. And unfortunately the nmake executable vendored by visual studio is installed in a directory that contains spaces.

To avoid any headaches on that regards, one can simply symlink the executable to a space-less folder. On my setup, I did it using the GUI tool for this called link shell extension. Here is the resulting symlink:

> (get-item C:\tools\nmake_symbolic_link\nmake.exe).target
..\..\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\nmake.exe

Makefile.win

Then, create a file called Makefile.win, that contain the exact instruction to build your project. For example, it could look like:

build:
	C:\Python27\python.exe C:\sources\my_project\in-hous-build-system\build-it.py --foo --bar --force --config Debug

then, one can test if this makefile works correctly by running from the Visual Studio Command Prompt

nmake build

.local.vimrc

Finally, we use the excellent vim plugin https://github.com/thinca/vim-localrc to save the vim settings only for that project. Here, the file would be in C:\sources\my_project\.local.vimrc and contain the following lines

" use forward slashes in path
let &l:makeprg="C:/tools/nmake_symbolic_link/nmake.exe -f C:/sources/my_project/Makefile.win /NOLOGO"
" Adjust according to the format used by your scripts
setlocal errorformat=%f(%l):\ %m,error

Now, open any file in your project directory and run :make to build from vim directly, and process any build error directly from there.

Leave a Comment