防止 Visual Studio 在 ASP.Net MVC 视图中自动缩进 C# 代码
我正在编辑 HTML 的视图中,例如,我可能需要在 <% %> 内添加一行 C# 代码。标签..
如果 C# 代码在我按 Enter 或完成命令后包含像 { 或 } 这样的括号,VS 会自动将该行扩展到 2 行,以自动缩进括号。
这真的很烦人,因为我不在代码视图中,我只是希望我的视图看起来超级干净,因此保持 C# 缩进与我输入的完全相同。
知道如何禁用它吗???
非常感谢..
I am in a view editing HTML and I may for example need one line of C# code inside <% %> tags..
If that C# code contains a bracket like { or } after I press enter or complete the command, VS automatically spreads the line over 2 lines to kind of auto-indent the brackets.
It's really annoying because I am not in code view, I just want my view to look super clean and therefore keep the C# indentation exactly how I typed it in.
Any idea how to disable this???
Many thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个 Visual Studio 自动缩进操作都保存在撤消历史记录中。这意味着,如果在自动缩进后立即按 Ctrl+Z(撤消),自动缩进将被取消,代码将恢复到初始缩进。此撤消操作不会影响您输入的任何字符,只会影响自动缩进。
它仍然很烦人,因为它需要额外的键盘输入,但对于许多情况来说,这是一个足够好的解决方法。
Every Visual Studio auto-indent operation is being saved in the Undo history. This means that if you press Ctrl+Z (undo) immediately after the auto-indent, it will be canceled and the code will be reverted to the initial indentation. This undo operation will not affect any characters that you have entered, only the auto-indentation.
It is still annoying, since it requires an additional keyboard input, but for many situations it is a good enough workaround.
是的,我也经历过这种事...讨厌 VS 这样做。 我所知,唯一的方法是禁用 C# 的“自动格式化已完成的块}”...
但据 选项|文本编辑器 | C# |格式化 |常规并取消选中它。
但是对于所有 C# 代码(不仅在视图中),您将失去此功能...
Yeah, I've experienced that too... Hate it when VS does that. But the only way to do it, that I know of, is disabling C#'s "Automatically format completed block on }"...
Go to Tools | Options | Text Editor | C# | Formatting | General and uncheck it.
BUT you will lose this feature for all C# code (not only in views)...