C 程式中的 VSCode 自動格式化通過對齊連續的注釋來生成此代碼:
if (true) { // if begin
// if inner part
int x = 3;
int a = 1; // some inner calculations
} // if end
// some outer calculations
int b = 1;
如何禁止注釋對齊以獲得下面的代碼?
if (true) { // if begin
// if inner part
int x = 3;
int a = 1; // some inner calculations
}// if end
// some outer calculations
int b = 1;
我只能通過添加空行來防止它。
uj5u.com熱心網友回復:
VS Code 的 Microsoft C/C 擴展默認使用 clang-format 作為格式化工具。clang-tidy是一個靜態分析工具,它本身也很好用,但它不是回答這個問題的工具。
clang 格式樣式選項:https : //clang.llvm.org/docs/ClangFormatStyleOptions.html
您想要的選項是AlignTrailingComments,您將其設定為 false。如果您只想更改一些引數,但要基于樣式,請使用clang-format -style=LLVM --dump-config > .clang-format專案根目錄中的內容轉儲該樣式。該命令假定使用 POSIX 或足夠接近的 shell(bash、fish、zsh 等)。它也可能在 Windows 中作業,我只是從未在那里嘗試過。
轉儲配置后,保留前兩行(語言和取消注釋 BasedOnStyle),然后您可以洗掉任何您不想更改的選項。保留您要更改的選項,更改它們,保存,退出等。更改 VS Code 以file默認首先查找樣式(我相信這是默認設定),您應該一切順利。
這是如上所述的 .clang 格式檔案的簡單示例:
---
Language: Cpp
BasedOnStyle: LLVM
AlignTrailingComments: true
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/408587.html
標籤:
下一篇:找不到Pygame模塊
