I am pretty new to Vim and I need some help with work-flow developing in C++.

Currently, I am using Sublime Text as my primary editor for the following work-flow:

Lets say I am working on RingBuffer class, for which I have

  • ring_buffer.h
  • ring_buffer.cpp
  • unittest\ring_buffer_mock.h
  • unittest\ring_buffer_test.cpp
  • and unittest\ring_buffer.makefile.

Each makefile has its own set of dependencies. Sublime Text allows you to add a build system, which runs a shell command defined by user in project file, and parses the output. To test the Ring Buffer, I go to menu->tools->BuildSystem->RingBuffer. So here is the question

  1. Can you recommend a good work-flow in VIM?
  2. Is it possible in local .vimrc to specify makefile, such as ring_buffer.makefile?

EDIT! First off, set makeprg=make\ -f\ ring_buffer.makefile works well, but it does not offer any automation. So I am going to ask a second question which can be found here:

Determining makefile based on source file name

  • 1. One of tons articles: alexeyshmalko.com/2014/using-vim-as-c-cpp-ide 2. set makeprg=make\ -f\ ring_buffer.makefile
    – Alex Kroll
    Commented Aug 4, 2015 at 14:27
  • What is the purpose of the '\' char after each option? Commented Aug 4, 2015 at 15:00
  • \ is a escaped space symbol. See :he makeprg for examples and explanations.
    – Alex Kroll
    Commented Aug 4, 2015 at 15:02
  • Thank you. Actually I did read the help, but being so new to VIM, it is hard to understand. Things that you advanced users take for granted are sometimes a mystery to a beginner like me. Commented Aug 4, 2015 at 15:24
  • If I wanted to add error window :copen, I tried the follwoing: set makeprg=make\ -f\ ring_buffer.makefile | copen, but it still goes to the terminal. Any way to prevent it from flashing the terminal? Commented Aug 4, 2015 at 15:58

1 Answer 1


I don't know much about C++ development, but in regard to your questions about good workflows and granular control with makefiles I'd tell you to look no further than tpope's vim-dispatch.

With this plugin you can use :Make to start an asynchronous build in the foreground (for longer build tasks you can append a ! to start it in the background instead). Just this command makes this plugin a must-have if you work with makefiles.

But there is more. Another cool command provided is :Dispatch, which might address a couple of your requests. It's basically like :Make but provides a bit more control:

:Dispatch picks a compiler by looking for either
CompilerSet makeprg={program}\ [arguments] or
CompilerSet makeprg={program} in compiler plugins.
To force a given {program} to use a given {compiler},
create ~/.vim/after/compiler/{compiler}.vim and add to
it a line like the following:

" CompilerSet makeprg={program}

You can have even more control by setting g:dispatch_compilers in your vimrc. This option takes a dictionary where the keys are commands you can call after :Dispatch and compiler plugins are the values:

let g:dispatch_compilers = {
    \ 'latex': 'tex',
    \ 'bundle exec': ''}

Make sure to read through the docs, there's definitely more to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.