Substitution rule for vim's Quickfix window when using WAF

written on Fri 18 July 2014

I have a C++ project with *.cpp files located in c:\project. I'm also using a pseudo-out-of-tree build system, which uses c:\project\build directory as an output directory for every executable, object file, autogenerated file, etc.

Normally, I'm launching vim when by current directory (PWD) is c:\project:

$ vim <file>

When I use :make command, my build tool launches and begins the project compilation step. In case of any errors, I'm getting the usual error list in the Quickfix window (:cope). The problem is that the build tool I'm using (btw, its name is waf and it's a very nice tool) is executed from the c:\project\build directory, not c:\project, so any references to source files will be printed out relatively to c:\project\build directory. This means that for this file: c:\project\main.cpp, in case of an error I'l get error message like:

..\main.cpp:9:0: <error message>

Vim's g++ parser takes this error line, extracts the filename from it (..\main.cpp), but it won't open it after I click enter, because vim session's PWD is c:\project. After clicking enter, vim tries to open c:\main.cpp.

I can just start vim from the c:\project\build directory and it's working, but this in turn causes problems with vim plugins like CtrlP, so I'd like to start vim session from project's root, not build's root.

So, is it possible to substitute the ..\ to an empty string? I was wondering, because apparently tools like gdb have some path substitution options (source path substitution).

It turns out it's possible, but outside vim. I've fixed this by creating a build script (m.cmd):

@echo off
waf 2>&1 | sed "s#^..\\##g"

and I did set :set makeprg=m.cmd in vim.

It works as expected.