How do you auto format code in Visual Studio?

user719550 picture user719550 · Apr 22, 2011 · Viewed 1.4M times · Source

I know Visual Studio can auto format to make my methods and loops indented properly, but I cannot find the setting.

Answer

Bogdan Verbenets picture Bogdan Verbenets · Apr 22, 2011

To format a selection: Ctrl+K, Ctrl+F

To format a document: Ctrl+K, Ctrl+D

See the pre-defined keyboard shortcuts. (These two are Edit.FormatSelection and Edit.FormatDocument.)

Note for macOS

On macOS, use the CMD ⌘ key instead of Ctrl:

  • To format a selection: CMD ⌘+K, CMD ⌘+F
  • To format a document: CMD ⌘+K, CMD ⌘+D