Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you auto format code in Visual Studio on save?

is there any way to auto-format HTML and Javascript code on saving in Visual Studio like Visual Studio Code?

like image 829
Mohammad Ali Rony Avatar asked Jan 21 '20 10:01

Mohammad Ali Rony


People also ask

How do I automatically format code in Visual Studio Code?

The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.

How do I Auto Save visual codes?

The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay. For more control over Auto Save , open User or Workspace settings and find the associated settings: files.


2 Answers

Since Visual Studio 2022 17.1 there is a builtin Feature to run code formatting on save (see devblogs.microsoft), meaning there is no need to install extensions like Format document on Save.

enter image description here

like image 154
kraego Avatar answered Sep 21 '22 16:09

kraego


The plugin Format document on Save seems to to do what you ask:

Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the Ctrl + E , D or Ctrl + E , F key shortcuts but with this extension the command Format Document is executed on Save.

like image 27
GrafiCode Avatar answered Sep 19 '22 16:09

GrafiCode