Skip to main content

Formatting Projects

Formatting should be automatic and consistent.

Visual Studio​

ActionDefault shortcut
Format documentCtrl+K, Ctrl+D
Format selectionCtrl+K, Ctrl+F

To check your bindings, open Edit → Advanced. To change them, go to Tools → Options → Environment → Keyboard and bind Edit.FormatDocument and Edit.FormatSelection.

Format on Save​

Go to Tools → Options → Text Editor → Code Cleanup and enable Run Code Cleanup profile on Save. Configure the profile to include Format document.

VS Code​

Install the C# Dev Kit (or the C# extension). Its formatter follows your .editorconfig.

ActionWindowsmacOSLinux
Format documentShift+Alt+FShift+Option+FCtrl+Shift+I
Format selectionCtrl+K, Ctrl+FCmd+K, Cmd+FCtrl+K, Ctrl+F

Format on Save​

Add the following to .vscode/settings.json:

{
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp",
"editor.formatOnSave": true
}
}