I am trying to come up with a way to handle C++ projects with Vim. I have sorted out syntax and code completion etc. to some extend. Now, I am curios to hear about how people handle their Build > Make > Run cycles for their projects.
This is what I have so far:
1) For the build
stage I use CMake. I am invoking CMake either from a terminal open just under my Vim window or through Vim using the vim-dispatch
plugin.
By doing something like this:
:Dispatch 'cd {my_project_dir}; rm -rf ./build/*; cd ./build; cmake ..'
This runs cmake and prepares the make
files.
2) For the make
stage, I am setting the makeprg
option of Vim for my current project and I am executing it with vim-dispatch using the :Make
wrapper.
It looks like that:
makeprg=cd {my_project_dir}/build && make
This compiles the code.
3) The final stage is running the compiled binary. For that I am using vim-dispatch as well. The run call looks like that:
:Dispatch {my_project_dir}/build/bin/myproject
All these stages seem to be working ok, what I am missing is an error check between those. Ideally, I would like to stop at stage (2) and not run the binary (which would be outdated) if the make
stage fails.
What would be the best way to solve this problem? Is there some kind of an access to the exit codes for each of these stages?
:!make && /path/to/exe
? That seems to be working fine for me.getqflist()
returns an empty list, or not (you could even parse the list to see if there are errors in it - useful if you expect to have warnings).