How do you auto format code in Visual Studio?

2019-01-07 01:32发布

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

21条回答
Melony?
2楼-- · 2019-01-07 01:37

Right click:

enter image description here

Works in VS 2015, maybe earlier version.

查看更多
地球回转人心会变
3楼-- · 2019-01-07 01:42
  1. Go to Tools -> Extensions & Updates and type "productivity" in search: 1
  2. Install 'Productivity Power Tools 2015'
  3. Restart VS.
  4. Go to Tools -> Options -> Productivity Power Tools -> Power Commands and check "Format document on save": 2
查看更多
够拽才男人
4楼-- · 2019-01-07 01:46

In VS 2017 Format Document is CTRL E + D.

But...if you want to add the Format Document button to a tool bar do this.
Right click on tool bar.
Select "Customize.."
Select the "Commands" Tab.
Select the "Toolbar" radio button.
Select "Text Editor" from the pull down next to the radio button (or what ever tool bar you want the botton on)

Now...

Click the Add Command button.
Categories: Edit
Commands: Document Format
Click OK

查看更多
【Aperson】
5楼-- · 2019-01-07 01:47

I have installed an extension named "Format document on Save" which formats the whole document every time you save it. For install it in VS15 or 17, on Tools just click the "Extensions and Updates...":

enter image description here

And then just go to "Online" at the left panel and search for "Format document on save" enter image description here

I hope it helps!.

查看更多
\"骚年 ilove
6楼-- · 2019-01-07 01:47

If you display the HTML Source Editing toolbar there is a "Format the Whole Document" button as well

查看更多
Melony?
7楼-- · 2019-01-07 01:48

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

查看更多
登录 后发表回答