Craig H
Craig H

Reputation: 7989

how to set makeprg in vim when your build system is compiling a copied version of the code

I have been using the the vim integrated make command to help with my build, fix, repeat cycle at work. We are in the process of moving to a new build system that I can easily change to using makeprg.

The problem is the new build system copies off the source code to a sandbox location before it builds, so when I get compile errors, vim opens up the copied file. I end up changing this copied file, and not the actual file in the main code path.

Is some way I can fix this by somehow telling vim what my code base path is?

Upvotes: 3

Views: 1741

Answers (1)

Dave Goodell
Dave Goodell

Reputation: 2153

There are at least three strategies you could use to fix this, unfortunately they'll all involve a bit more work than just telling vim a "code base path". Before choosing one, I'd recommend reading :help make_makeprg to get a good sense of the :make process "under the hood".

  1. Write a shell/perl/ruby/whatever script that filters the output from your build process and rewrites file names from /sandbox/src/blah.c to src/blah.c or /sandbox/src to src as appropriate. Then change makeprg to include the filter program when running make (in your .vimrc, add this: :set makeprg=make\ \\\|\ filter). This is probably pretty easy to do, but might be made trickier depending on what exact build system you are using.

  2. Change errorformat (see :help errorformat) to strip off the sandbox prefix for you. This might not be possible in some cases, depending on the exact output format from your build system.

  3. Add a QuickFixCmdPost autocommand that will rewrite the file paths in the quickfix window before you begin using :cnext and friends. If you haven't used Vim's autocommand feature before, I would try the other two strategies first. They are powerful and very useful, but they take some practice to get right.

Upvotes: 5

Related Questions