So far after installing the C++ extension tool, I can use Ctrl + K + F to auto-format my C++ code. However, I would like to make some modification, for example I would like to force the pointer alignment to be near the type, instead of next to the variable name, such as this rule:
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
How can I do this modification? I've tried to create a .clang-format file, but it doesn't work.
After some experiments, the simple solution is to add this line in the User Settings (settings.json):
"C_Cpp.clang_format_fallbackStyle": "{ PointerAlignment: Left}"
However, this settings allow me to keep my previous settings without breaking my function line:
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, ColumnLimit: 120, PointerAlignment: Left}"
Using "BasedOnStyle: Visual Studio" such as this line:
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Visual Studio, ColumnLimit: 120, PointerAlignment: Left}"
doesn't work. It is may be a bug. I used Visual Studio Code version 1.26.1.
Additionally, a .clangformat outside the workspace folder will still be applied. So, if this file is corrupt the auto-format will not work.
I use clang-format, which integrates quite well and is very configurable. See https://code.visualstudio.com/docs/cpp/cpp-ide#_code-formatting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With