如何自动格式化VS2012中的代码缩进?

时间:2013-04-17 13:55:58

标签: visual-studio-2012 format indentation auto-indent

如何在VS2012中自动格式化代码以节省输入和删除空格和标签的时间?

enter image description here

2 个答案:

答案 0 :(得分:29)

如果您想在输入文字时格式化代码,可以在工具\选项\文字编辑器区域中进行一些其他设置。

由于您的示例似乎是配置文件(XML),请查看XML编辑器。

enter image description here

否则,要随时格式化, @mitaka @Xaruth 的建议都是好的。

请注意,激活格式文档格式选择的按键会有所不同,具体取决于您在Visual Studio中处于活动状态的开发设置。要查看在VS副本中为命令分配了哪些击键,请在编辑菜单中查看。

enter image description here

答案 1 :(得分:6)

我使用以下组合自动格式化VS2012中代码的缩进。

web.config中未格式化的代码块: Unformatted xml block

Ctrl + A 选择要在VS2012中格式化的文件中的所有代码。或者您可以手动选择一段代码。

Ctrl + K ,然后 Ctrl + F 会使用适当的缩进格式化代码。

格式化代码块 enter image description here