0

I have read this How can I autoformat/indent C code in vim? about how to format C/C++ code, but I want to autoformat the code when I'm saving the file, like how vim-go calls gofmt when saving Golang code.

How can I configure my vimrc? I'm using clang-format, and have installed vim-clang-format with spf13vim using Vundle.

Rory O'Kane
  • 27,337
  • 11
  • 91
  • 127
mickeyandkaka
  • 1,401
  • 1
  • 10
  • 21

1 Answers1

2

Found it.

  • g:clang_format#detect_style_file

When this variable's value is 1, vim-clang-format automatically detects the style file like .clang-format or _clang-format and applies the style to formatting.

So this code should be in the .vimrc:

let g:clang_format#auto_format=1
Rory O'Kane
  • 27,337
  • 11
  • 91
  • 127
mickeyandkaka
  • 1,401
  • 1
  • 10
  • 21