Skip to content

Instantly share code, notes, and snippets.

@9sako6
Last active February 18, 2024 05:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9sako6/458def885387e8dcd2f0f2742a1dc3e4 to your computer and use it in GitHub Desktop.
Save 9sako6/458def885387e8dcd2f0f2742a1dc3e4 to your computer and use it in GitHub Desktop.
VSCode C++整形時の行頭カッコやめたい

VSCode C++整形時の行頭カッコやめたい

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

参考

vscodeのC++用コード整形設定(clang-formatの設定)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment