VSCodeにC++拡張を入れていると、
Ctrl+Alt+F
でコードを整形できる。(環境によってキーバインドは違うかもしれない)
デフォルトでは{
の前に改行が入り、このように整形される。
void f()
{
// your code
}
{
の前に改行が入るのが嫌なので下のようにしたい。
void f() {
// your code
}
settings.json
を開き、以下の設定を加えると目的の整形ができるようになる。
"C_Cpp.clang_format_style": "{ BreakBeforeBraces: Attach, IndentWidth: 4 }"
Googleスタイルを使う手もある。
"C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4 }"