I cannot convince vim to apply the coding-style I'd like to (cindent and friends).

However, integrating clang-format.py (which uses the .clang-format of my project) actually makes me totally happy.

Except that I have the reflex of using the = + motion-command. Which is actually very nice to indent a region or the whole file.

How can I instruct vim to override the default functionality? I read about equalprg, but I'm unsure how to set it to make it work with clang-format.

  • 4
    How about installing Rhysd's vim-clang-format plugin, together with its requirements (especially vim-operator-user), and then map = to <Plug>(operator-clang-format)? Plugin link: github.com/rhysd/vim-clang-format
    – VanLaser
    Feb 17, 2016 at 9:49
  • Thank you @VanLaser Do you also know how to make it work with the motion: == for one line and gg=G for the whole buffer?
    – Patrick B.
    Feb 17, 2016 at 10:32
  • @VanLaser sorry for my reluctance - I was simply not believing: your comment works as expected. Make it an answer please.
    – Patrick B.
    Feb 17, 2016 at 11:54

1 Answer 1


If you have nothing against a plugin install, Rhysd's vim-clang-format may be a valid solution, instead of a custom equalprg.

As the documentation states, with Kana's vim-operator-user dependency installed, you can map = to <Plug>(operator-clang-format) (to function as a full operator) and use it with motions / text-objects such as == or =G.

You should create a buffer local mapping, only for C,C++ and Objective-C filetypes, to let default = otherwise untouched:

autocmd FileType c,cpp,objc map <buffer> = <Plug>(operator-clang-format)

Your Answer

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

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