visual-studio-code

VScode not obeying "Tab Size" setting with format action


VScode is ignoring the Tab Size setting.

I'm using VScode to edit some c++ code. I have

editor.DetectIndentation: false
editor.InsertSpaces: true
editor.TabSize: 4

set in both User and Workspace. I have tried restarting the editor. At the bottom of the window it says:

Spaces:4  UTF-8 LF C++ Linux

When I type in lines, tab inserts 4 spaces, but when I format the document (Ctrl-Shift-I), everything reverts back to 2-space indentation.

I have no .editorconfig file

Were is the magic setting that's over riding my TabSize of 4?

Thanks.


Solution

  • In my case, the culprit was the setting: C_Cpp: Clang_format_fallback Style

    It was set to Google. I guess Google likes 2 spaces for their C++ code. I changed it to Visual Studio which uses 4 spaces. The upshot is that the tabSize is ignored if the format style uses something else.