Search code examples
visual-studio-codeclang-format

clang-format file not working in Visual Studio code


I have put a .clang-format file in my workspace. But that formatting is not applied on my code. I have checked the settings and they are set to None for fallback-style and file for clang_format_style.

The good news is that the fallback Style doesn't work anymore. Which means when I try to Format the Document or Selection nothing happens.

This is what I did to make my custom formatting:

visualstudio.com: Edit C++ in Visual Studio Code

But there is something missing and the formatting is no happening. This is what my .clang-format in my workspace looks like:

{ 
UseTab: 14, 
IndentWidth: 4,
 BreakBeforeBraces: BS_Attach,
 AllowShortIfStatementsOnASingleLine: false,
 IndentCaseLabels: false,
 ColumnLimit: 0 
}

Solution

  • I've just suffered from this issue, but it appears to be a minor bug in VS Code. In my settings I had Editor: Format On Save turned on, C_Cpp: Clang_format_style set to file, and C_Cpp: Formatting set to Default (which is stated as clang-format). But nothing happened on save.

    To 'fix' it, I forcibly triggered a format by selecting some code and clicking Format Selection which then gave me a dialog whining about there being multiple formatters available and that I have to pick one from the command palette. It looks like the builtin MS Intellisense one and clang-format were fighting for dominance - despite the fact that clang-format was listed as default in the settings! After selecting clang-format here, it was all fine again.