How do you auto format code in Visual Studio?

To format a selection: Ctrl+KCtrl+F

To format a document: Ctrl+KCtrl+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 ⌘+KCMD ⌘+F
  • To format a document: CMD ⌘+KCMD ⌘+D

Leave a Comment