EditorConfig ファイルをプロジェクトに追加して、プロジェクトに貢献するすべてのユーザーに一貫したコード スタイルを適用するように C++ の書式設定を構成できます。 Visual StudioとVisual Studio Codeの両方に、グローバル Visual Studio C++ 書式設定設定ごとに EditorConfig サポートが組み込まれています。 EditorConfig 設定は、 .editorconfig ファイルに格納されます。 そのファイルがプロジェクトに存在する場合は、Visual Studioの書式設定よりも優先されます。
このドキュメントでは、Visual StudioとVisual Studio Codeでサポートされているすべての EditorConfig C++ 書式設定の一覧を示します。
C++ には、書式設定されていない追加の .editorconfig 設定があります。 これらの設定は、構成する機能と共に文書化されています。
-
インクルード クリーンアップ設定 (
cpp_include_cleanup_*とcpp_sort_includes_*) については、「Visual Studioでの C/C++ インクルード クリーンアップの構成」を参照してください。 -
#include入力候補 (cpp_includes_use_forward_slashとcpp_includes_style) の IntelliSense 設定については、「言語の構成> C/C++ > IntelliSense オプション」を参照してください。
詳細情報については、以下をご覧ください。
- Visual Studioで EditorConfig ファイルを使用する場合は、「EditorConfig を使用して一貫性のあるコーディング スタイルを定義する」を参照してください。
- clang の書式設定に基づいて EditorConfig ファイルを手動で作成する方法については、 clangformat を参照してください。 そのファイル
.editorconfigの名前を変更し、プロジェクトに保存します。
C++ の書式設定規則
C++ の書式設定 EditorConfig の設定には、プレフィックスとして cpp_ が付いています。
.editorconfig ファイルの例を次に示します。
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
cpp_indent_case_contents_when_block = true
cpp_new_line_before_open_brace_namespace = same_line
この記事の残りの部分では、Visual Studioと VS Code でサポートされているすべての EditorConfig C++ 書式設定設定の一覧を示します。
インデントの設定
中かっこをインデントする
- 名前:
cpp_indent_braces - 値:
true、false
各行を相対的にインデントする
- 名前:
cpp_indent_multi_line_relative_to - 値:
-
outermost_parenthesis- 新しい行を入力すると、最も外側の開いているかっこに対して相対的にインデントされます。 -
innermost_parenthesis- 新しい行を入力すると、最も内側の開いているかっこに対して相対的にインデントされます。 -
statement_begin- 新しい行を入力すると、現在のステートメントの先頭に相対的にインデントされます。
-
かっこ内で、入力時に新しい行を配置する
- 名前:
cpp_indent_within_parentheses - 値:
-
align_to_parenthesis- 内容を左かっこに合わせます。 -
indent- 新しい行をインデントします。
-
既存のコードでは、かっこ内の新しい行の配置に設定を使用しないでください
- 名前:
cpp_indent_preserve_within_parentheses - 値:
true、false
大文字と小文字の内容をインデントする
- 名前:
cpp_indent_case_contents - 値:
true、false
インデントケースラベル
- 名前:
cpp_indent_case_labels - 値:
true、false
case ステートメントの後に中かっこをインデントする
- 名前:
cpp_indent_case_contents_when_block - 値:
true、false
パラメーターとして使用されるラムダのインデント中かっこ
- 名前:
cpp_indent_lambda_braces_when_parameter - 値:
true、false
ジャンプ ラベルの位置
- 名前:
cpp_indent_goto_labels - 値:
-
one_left- 左に 1 つのインデント -
leftmost_column- 左端の列に移動する -
none- インデントのままにする
-
プリプロセッサ ディレクティブの位置
- 名前:
cpp_indent_preprocessor - 値:
-
one_left- 左に 1 つのインデント -
leftmost_column- 左端の列に移動する -
none- インデントのままにする
-
アクセス指定子のインデント
- 名前:
cpp_indent_access_specifiers - 値:
true、false
名前空間の内容をインデントする
- 名前:
cpp_indent_namespace_contents - 値:
true、false
コメントのインデントを保持する
- 名前:
cpp_indent_preserve_comments - 値:
true、false
改行の設定
名前空間のオープン 中かっこの位置
- 名前:
cpp_new_line_before_open_brace_namespace - 値:
-
new_line- 新しい行に移動する -
same_line- 同じ行に保持しますが、前にスペースを追加します -
ignore- 自動的に位置を変更しない
-
型の開いた中かっこの位置
- 名前:
cpp_new_line_before_open_brace_type - 値:
-
new_line- 新しい行に移動する -
same_line- 同じ行に保持しますが、前にスペースを追加します -
ignore- 自動的に位置を変更しない
-
関数のオープン 中かっこの位置
- 名前:
cpp_new_line_before_open_brace_function - 値:
-
new_line- 新しい行に移動する -
same_line- 同じ行に保持しますが、前にスペースを追加します -
ignore- 自動的に位置を変更しない
-
コントロール ブロックの開いた中かっこの位置
- 名前:
cpp_new_line_before_open_brace_block - 値:
-
new_line- 新しい行に移動する -
same_line- 同じ行に保持しますが、前にスペースを追加します -
ignore- 自動的に位置を変更しない
-
ラムダのオープン 中かっこの位置
- 名前:
cpp_new_line_before_open_brace_lambda - 値:
-
new_line- 新しい行に移動する -
same_line- 同じ行に保持しますが、前にスペースを追加します -
ignore- 自動的に位置を変更しない
-
スコープの中かっこを別々の行に配置する
- 名前:
cpp_new_line_scope_braces_on_separate_lines - 値:
true、false
空の型の場合は、右中かっこを左中かっこと同じ行に移動します
- 名前:
cpp_new_line_close_brace_same_line_empty_type - 値:
true、false
空の関数本体の場合は、右中かっこを左中かっこと同じ行に移動します
- 名前:
cpp_new_line_close_brace_same_line_empty_function - 値:
true、false
"catch" と同様のキーワードを新しい行に配置する
- 名前:
cpp_new_line_before_catch - 値:
true、false
新しい行に 'else' を配置する
- 名前:
cpp_new_line_before_else - 値:
true、false
"while" を新しい行の do-while ループに配置する
- 名前:
cpp_new_line_before_while_in_do_while - 値:
true、false
間隔の設定
関数名と引数リストのかっこの間の間隔
- 名前:
cpp_space_before_function_open_parenthesis - 値:
-
insert- スペースを挿入する -
remove- スペースを削除する -
ignore- スペースを変更しない
-
引数リストのかっこ内にスペースを挿入する
- 名前
cpp_space_within_parameter_list_parentheses値:true、false
引数リストが空の場合にかっこの間にスペースを挿入する
- 名前:
cpp_space_between_empty_parameter_list_parentheses - 値:
true、false
制御フロー ステートメントでキーワードと左かっこの間にスペースを挿入する
- 名前:
cpp_space_after_keywords_in_control_flow_statements - 値:
true、false
コントロール ステートメントのかっこ内にスペースを挿入する
- 名前:
cpp_space_within_control_flow_statement_parentheses - 値:
true、false
ラムダ引数リストのかっこを開く前にスペースを挿入する
- 名前:
cpp_space_before_lambda_open_parenthesis - 値:
true、false
C スタイルのキャストのかっこ内にスペースを挿入する
- 名前:
cpp_space_within_cast_parentheses - 値:
true、false
C スタイルキャストの終わりかっこの後にスペースを挿入する
- 名前:
cpp_space_after_cast_close_parenthesis - 値:
true、false
かっこで囲まれた式のかっこ内にスペースを挿入する
- 名前:
cpp_space_within_expression_parentheses - 値:
true、false
ブロックの中かっこを開く前にスペースを挿入する
- 名前:
cpp_space_before_block_open_brace - 値:
true、false
空の中かっこの間にスペースを挿入する
- 名前:
cpp_space_between_empty_braces - 値:
true、false
均一な初期化リストと初期化子リストの中かっこを開く前にスペースを挿入する
- 名前:
cpp_space_before_initializer_list_open_brace - 値:
true、false
均一な初期化リストと初期化子リストの中かっこ内にスペースを挿入する
- 名前:
cpp_space_within_initializer_list_braces - 値:
true、false
均一な初期化リストと初期化子リスト内のスペースを保持する
- 名前:
cpp_space_preserve_in_initializer_list - 値:
true、false
角かっこを開く前にスペースを挿入する
- 名前:
cpp_space_before_open_square_bracket - 値:
true、false
角かっこ内にスペースを挿入する
- 名前:
cpp_space_within_square_brackets - 値:
true、false
空の角かっこの前にスペースを挿入する
- 名前:
cpp_space_before_empty_square_brackets - 値:
true、false
空の角かっこの間にスペースを挿入する
- 名前:
cpp_space_between_empty_square_brackets - 値:
true、false
多次元配列の角かっこをグループ化する
- 名前:
cpp_space_group_square_brackets - 値:
true、false
ラムダの角かっこ内にスペースを挿入する
- 名前:
cpp_space_within_lambda_brackets - 値:
true、false
SpaceBetweenEmptyLambdaBrackets
- 名前:
cpp_space_between_empty_lambda_brackets - 値:
true、false
コンマの前にスペースを挿入する
- 名前:
cpp_space_before_comma - 値:
true、false
コンマの後にスペースを挿入する
- 名前:
cpp_space_after_comma - 値:
true、false
メンバー演算子の前後にスペースを削除する
- 名前:
cpp_space_remove_around_member_operators - 値:
true、false
型宣言の base のコロンの前にスペースを挿入する
- 名前:
cpp_space_before_inheritance_colon - 値:
true、false
コンストラクターのコロンの前にスペースを挿入する
- 名前:
cpp_space_before_constructor_colon - 値:
true、false
セミコロンの前のスペースを削除する
- 名前:
cpp_space_remove_before_semicolon - 値:
true、false
セミコロンの後にスペースを挿入する
- 名前:
cpp_space_after_semicolon - 値:
true、false
単項演算子とそのオペランドの間のスペースを削除する
- 名前:
cpp_space_remove_around_unary_operator - 値:
true、false
二項演算子の間隔
- 名前:
cpp_space_around_binary_operator - 値:
-
insert- 二項演算子の前後にスペースを挿入します。 -
remove- 二項演算子の周囲のスペースを削除します。 -
ignore- 二項演算子の周囲にスペースを変更しないでください。
-
代入演算子の間隔
- 名前:
cpp_space_around_assignment_operator - 値:
-
insert- 代入演算子の周囲にスペースを挿入します。 -
remove- 代入演算子の周囲のスペースを削除します。 -
ignore- 代入演算子の周囲のスペースを変更しないでください。
-
ポインター/参照の配置
- 名前:
cpp_space_pointer_reference_alignment - 値:
-
left- 左揃え。 -
center- 中央揃え -
right- 右揃え。 -
ignore- 変更しない。
-
条件付き演算子の間隔
- 名前:
cpp_space_around_ternary_operator - 値:
-
insert- 条件演算子の周囲にスペースを挿入します。 -
remove- 条件演算子の周囲のスペースを削除します。 -
ignore- 条件付き演算子の周囲にスペースを変更しないでください。
-
折り返しオプション
ブロックの折り返しオプション
- 名前:
cpp_wrap_preserve_blocks - 値:
-
one_liners- 1 行のコード ブロックをラップしないでください。 -
all_one_line_scopes- 開始中かっこと右中かっこが次の行にあるコード ブロックをラップしないでください。 -
never- 常にブロックに新しい線の設定を適用します。
-