'VSCode - disable comments auto-formatting for C code
I just installed an extension prettier in vscode to autoformat my code. However all the comments in my code are being moved towards the left. Which I don't want. Before formatting: enter image description here
After formatting: enter image description here
The thing is I want my comments to stay exactly where they were before. I don't want them being moved. Other things I'm absolutely fine with. I just want the comments to be ignored when formatting.
Is it even possible? If so could you help me with this? It doesn't have to be only with Prettier extension. I'm down to use other formatting extensions if needed. Thank you.
Solution 1:[1]
For VSCode, you can edit your settings.json file to specify your default clang format fallback style. This documentation will tell you all parameters you can use for the setting: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
For reference, my setting:
"C_Cpp.clang_format_fallbackStyle": " {BasedOnStyle: Google, AllowShortCaseLabelsOnASingleLine: true, AlignConsecutiveDeclarations: true, AllowShortFunctionsOnASingleLine: All, AlignTrailingComments: true, Language: Cpp, AlwaysBreakAfterReturnType: None, PenaltyReturnTypeOnItsOwnLine: 9999, PointerAlignment: Left, SortIncludes: true, IndentWidth: 4, ColumnLimit: 0, BreakBeforeBraces: Allman, SpacesBeforeTrailingComments: 5, AlignAfterOpenBracket: true, AlignConsecutiveAssignments: true, AlignConsecutiveMacros : true}",
Solution 2:[2]
With this site description, you should set the 'ReflowComments' keyword to false, and here is my personal setting in setting.json
mysetting:
"C_Cpp.clang_format_fallbackStyle": "{BasedOnStyle: Google,IndentWidth: 4,ReflowComments: false}"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Joe Davis |
Solution 2 | xing cui |