Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code formatting for "{ }"

I'm on Ubuntu. C++ in Visual Studio Code automatically lints like

if (condition == true) {   DoStuff(); } 

Instead I want to do :

if (condition == true) {   DoStuff(); } 

How do I do that?

I've already installed the C/C++ extension from the marketplace.

like image 519
radbrawler Avatar asked Aug 22 '17 17:08

radbrawler


People also ask

How do I fix Visual Studio formatting code?

On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.

How do I add formatting in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.


1 Answers

base on @Chris Drew's answer

  1. Go Preferences -> Settings
  2. Search for C_Cpp.clang_format_fallbackStyle
  3. Click Edit, Copy to Settings
  4. Change from "Visual Studio" to "{ BasedOnStyle: Google, IndentWidth: 4 }"

e.g.

  • "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}"
  • btw ColumnLimit: 0 is helpful too, because google limit will break your code to next line when you do not need it.

If you want more:

  • check https://clang.llvm.org/docs/ClangFormatStyleOptions.html
  • customize your functionality to "C_Cpp.clang_format_fallbackStyle" for your loved favor.

More detail:

English: https://medium.com/@zamhuang/vscode-how-to-customize-c-s-coding-style-in-vscode-ad16d87e93bf

Taiwan: https://medium.com/@zamhuang/vscode-%E5%A6%82%E4%BD%95%E5%9C%A8-vscode-%E4%B8%8A%E8%87%AA%E5%AE%9A%E7%BE%A9-c-%E7%9A%84-coding-style-c8eb199c57ce

like image 190
Zam Avatar answered Oct 11 '22 17:10

Zam