简体   繁体   中英

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?

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.

In 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 .

在此处输入图像描述

we can also add vs code extension for auto formatting like "PRETTIER" with this vs code will format our code just do one more thing with this is go to settings in vs code and search for format on save and enable it after adding prettier

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM