visual-studioindentation

How do you auto format code in Visual Studio?


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


Solution

  • 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: