Formatting settings in Visual Studio 2019 use K&R-derived layout and more.
K&R layout
For set K&R layout in Visual Studio 2019, from top menu: Tools -> Options -> Text Editor -> C/C++ -> Formatting options:
-
move open braces to a new line for namespaces
namespace Namespace1 { namespace Namespace2 { } } -
keep open braces on the same line for types
namespace Namespace1 class Class1 { }; -
move open braces to a new line for functions
void Function1() { } -
keep open braces on the same line for control blocks
void Function() { while (cin >> word) { if (word.length() > 2) { } } } -
keep open braces on the same line for lambadas
void Function() { auto lambda1 = []() { }; auto lambda2 = [&]() { }; } -
place braces on separate lines for scopes
void Function() { // Scope { int i; } } -
keep close braces on the same line for empty types, function bodies.
class MyException {} MyClass::~MyClass() {} -
place ‘catch’, ‘else’ and similar keywords on a new line
try { } catch (...) { } if (a < b) { } else { }

Indent
For set indent in Visual Studio 2019, from top menu: Tools -> Options -> Text Editor -> Tabs options:

Tips: If you set the indentation to Keep tabs, then 8 spaces will be displayed on Github. You can add ?ts=4 to a diff or file URL will display tab characters as 4 spaces wide instead of the default 8. For more details and other nuggets, please see github-cheat-sheet
Line width
For set line width in Visual Studio 2019:
-
From top menu:
Extensions->Manage Extensionsoptions. (Ctrl + Shift + X) -
Search(Ctrl + E)
editor Guidelinesin the upper right corner and Download theeditor Guidelines.
-
Close Visual Studio 2019 and start installing this extension.

-
For set line width, from top menu:
View->Other Windows->Command Windowoptions.Edit.AddGuidelineandEdit.RemoveGuidelinecommands used to set the line width and remove the line width.i.e. to place a guide to the right of column 110, use
Edit.AddGuideline 110.
Reset the settings to default
For reset the settings in Visual Studio 2019, from top menu: Tools -> Import and Export Settings...options, you can also import or export settings.
