Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 219
user719550 Avatar asked Apr 22 '11 13:04

user719550


People also ask

What is the fastest way to format code in Visual Studio?

In the default configuration for Visual Studio Code, the command can be run using the shortcut Alt+Shift+F. To format a range, in an already opened project, open the document that you want to modify, select the specific range to format, right-click, and select Format Selection.

What is auto formatting code?

PDT can auto-format your code according to set standards in order to make it easily navigable and readable. Your code will be automatically formatted according to the settings defined in the PHP Formatter Preferences page, accessed from Window | Preferences | PHP Formatter.


1 Answers

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
like image 187
Bogdan Verbenets Avatar answered Sep 20 '22 08:09

Bogdan Verbenets