Samuel Hetteš
Samuel Hetteš

Reputation: 3

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.

Upvotes: 0

Views: 2222

Answers (2)

cui xingxing
cui xingxing

Reputation: 301

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}"

Upvotes: 0

Joe Davis
Joe Davis

Reputation: 333

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}",

Upvotes: 1

Related Questions