How can i configure clang format without .clang-format file in every workspace?

Christoph S. picture Christoph S. · Nov 2, 2016 · Viewed 7.3k times · Source

I want to configure clang-format without having to copy my .clang-format file to every new workspace.

In my settings.json I currently have

"C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4, IndentCaseLabels: false, TabWidth: 4, UseTab: ForIndentation, ColumnLimit: 0}",
"C_Cpp.clang_format_fallbackStyle": "Google"

The description for C_Cpp.clang_format_style says

Coding style, currently supports: Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit. Use "file" to load the style from a .clang-format file in the current or parent directory. Use "{key: value, ...}" to set specific parameters, e.g.: "{ BasedOnStyle: LLVM, IndentWidth: 8 }"

Which made me think my approach would work, which it doesn't. When I use the auto format it always uses the Google fallbackStyle.

Is this just not possible or am I doing something wrong here?

Answer

joelfischerr picture joelfischerr · May 23, 2018

I just had the same problem and found that your approach using (I have changed only the formatting)

"C_Cpp.clang_format_style": "{BasedOnStyle: Google, 
IndentWidth: 4, 
IndentCaseLabels: false, 
TabWidth: 4, UseTab: ForIndentation, 
ColumnLimit: 0}",

does work.