I am using visual studio code with c++. When I format my code (Ctrl-k,Ctrl-f) it removes the spaces I place after/before open/close parentheses. I have the setting to add these spaces enabled and also see them in the settings.json file. I’m not using a prettier extension. I use only a c++ light theme extension, cmake and cmake tools extensions. The formatting is working otherwise, perhaps, only because I am fine with the default formatting except the extra spaces. Trivial but it’s driving me crazy. Does anyone have an idea how to make the formatted pay attention to the settings? Thanks, Eddie
2 Answers
The best way I know to solve this problem is to install the C/C++ extension by Microsoft (C/C++ IntelliSense).
After installing it, go to extension settings and choose between User and Workspace settings. What you need to adjust are these two lines:
- C_Cpp: Clang_format_fallback Style and
- C_Cpp: Clang_format_style
Based on your personal preferences, choose the CPP style out of those listed in extension settings (Google, LLVM, Chromium, Mozilla, etc.)
In addition, you might want to use extended settings as described here, e.g. "{BasedOnStyle: Google, ColumnLimit: 0}"
Moreover, there is another convenient way how you can adjust your formatting settings in VS Code's settings file:
- Go to your VS Code and open your workspace / any file
- If you are on Mac, press "cmd + Shift + P" and a console will appear
- Remove the caret ">" and type "settings"; you'll see two files: 1) settings.json in the .vscode folder and 2) settings.json in your system user folder. The first one is responsible for your workspace settings and the second one – for your user-wide settings.
- Each and every setting you change in your C/C++ extension is reflected in these files. Try to experiment with them. Changing the workspace file settings is useful when you work in a team and need to have the same formatting settings shared across all team members.
Take a look at these screenshots for reference:
Good luck!!

- 178
- 1
- 1
- 7
-
Thanks for the pointers. That got me looking in the right place. I fiddled with it some more and finally put a .clang_format file in the project directory. (There is probably a better place for it.) I am using wxWidgets and I found one buried in that. I copied it and made the appropriate mods for spacing and it is not putting the spaces where I want them. Wow, I write beautiful code (though, it would be nice if it would run without crashing). Thanks again. Eddie – EddieM Feb 23 '21 at 16:28
To remove the space before the opening bracket in C++ code formatting using the default "C/C++" formatter in VS Code, you can follow these steps:
- Open your VS Code settings by pressing
Ctrl + ,
(comma) or by navigating to "File" > "Preferences" > "Settings." - Click on the "Open Settings (JSON)" button on the top-right corner to open the
settings.json
file. - Add the following configuration to the
settings.json
file:
"C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, SpaceBeforeParens: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, IndentBraces: Attach, NamespaceIndentation: All, FixNamespaceComments: false }",
- Save the
settings.json
file and close it. - Restart VS Code for the changes to take effect.
NOTE:
With the updated configuration, the option "SpaceBeforeOpenParenthesis"
is set to false
, which removes the space before the opening bracket.
By following these steps, you can customize formatting for C/C++ in VS Code to remove the space for opening brackets in your C++ code formatting.
Make sure that default C/C++ Formatter is set:

- 89
- 10