Using MacOS for example, an ideal method of configuring clang-format for VS Code is to first install clang-format with Homebrew:
brew install clang-format
Then, use it to export the full style settings to ~/.clang-format:
clang-format -style=google -dump-config > ~/.clang-format
Then, perform the following in VS Code:
- Go to Code/File -> Preferences -> Settingsand define the following parameters under User Settings:
- "C_Cpp.clang_format_path": "/usr/local/opt/llvm/bin/clang-format"
- "C_Cpp.clang_format_style": "Google"
- "C_Cpp.clang_format_fallbackStyle": "Google"
- "C_Cpp.intelliSenseEngine": "Tag Parser"
This sets the formatter to the clang-formatter installed with Homebrew, which will automatically pull your style settings from the ~/.clang-format file you just created. This way, you can change every parameter in the style as desired and not just a subset of these.
The last parameter, C_Cpp.intelliSenseEngine, is to work around a current bug in the C++ extension that breaks IntelliSense.