How To Auto Format Code in Visual Studio 2022?

Formatting code allows you to improve the readability of the code, and as a result editing. The Visual Studio 2022 allows you to format both selected sections of code and the entire document. Let’s show how it works using an example of HTML code. Also this is applicable for any code like C#.

Format Entire Document – CTRL-E, D

 Hot-Key:  CTRL-E, D

 Menu:  Edit -> Advanced -> Format Document

Format Entire Document CTRL-E, D

Document Formatting Example – Before and After

Document Formatting Before After html example

Format Selection – CTRL-E, F

 Hot-key : CTRL-E, F

 Menu:  Edit -> Advanced -> Format Selection
Format Selection

Selection Formatting Example – Before and After

selection formatting example vs 2022

There is also another interesting way to do formatting – Add ‘Format Selection’ In the Context Menu. You may interested in how to set conditional breakpoints in Visual Studio.

Leave a Comment