LoginSignup
1
0

VSCodeのfomatでforやifの後にくる始めかっこの位置を新しい行にしたくない[C++]

Last updated at Posted at 2023-08-27

結論

C/C++: Generate EditorConfig contents from VC Format settingsを実行すると.editorconfigが作成され、そのデフォルト設定によってforやifの後にくるブロックの始めかっこの位置が新しい行にならなくなる。
image.png

前提

以下のextensionが導入されていること

比較

フォーマット前

sample.cpp
#include <bits/stdc++.h>

using namespace std;

int main(){
  int n;
  cin>>n;
  if(n%2==0){
    cout<<"Even number!"<<endl;
  }else{
    cout<<"Odd number!"<<endl;
  }
  return 0;
}

フォーマット後(.editorconfig作成前)

sample.cpp
#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  if (n % 2 == 0)
  {
    cout << "Even number!" << endl;
  }
  else
  {
    cout << "Odd number!" << endl;
  }
  return 0;
}

フォーマット後(.editorconfig作成後)

sample.cpp
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "Even number!" << endl;
  }
  else {
    cout << "Odd number!" << endl;
  }
  return 0;
}

備考

  • .editorconfigとはワークスペースレベルでコードのformat形式を指定するための設定ファイルであり、デフォルトからいい感じの設定になっていますが、必要に応じて以下の書式規則のガイドを見ながら設定を調整しても良さそうです。

  • SettingsのC_Cpp.vcFormat配下にformatに関する設定項目があるようで、そちらでも同様に設定が可能なようです。ただしこちらよりも.editorconfigで設定した内容の方が優先されます。
    image.png
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0