Visual Studio 2010 - 大括号自动对齐已更改,如何修复此问题?
更新:因为我认为这是我最常关注的问题之一,所以几年后我应该指出我发现的此问题的最常见原因:代码中其他地方的语法错误。 100% 的情况下,我都会遇到这种情况,这是因为我忘记了另一段代码的花括号,或者我有一个悬空的 if,或者之前的一行代码我没有完成。首先检查 IDE 错误是否有“) 或 }预期”之类的内容
原始问题:
我觉得这是一个一直愚蠢的问题,但我不知道如何解决这个问题,谷歌也没有发现任何结果。
在 Visual Studio 中,当我输入:
try {
}
VS 会自动将其重新格式化为
try
{
}
但现在它只是将其保留在第一个。我假设我不小心按下了热键或其他东西。请帮我解决这个问题吗?
Update: Since I see this is one of my most looked at questions, now a few years later I should point out what I found to be the most common cause of this problem: bad syntax elsewhere in your code. 100% of the time I've had this happen, it was because I'd forgotten a curly brace for another block of code, or I had a dangling if, or an earlier line of code I didn't finish. Check for IDE errors first for something like ") or } expected"
Original Question:
I feel like this is an all time dumb question to ask, but I have no idea how to fix this and google is turning up nothing.
In visual studio, when I type:
try {
}
VS would automatically reformat it to
try
{
}
But now it's just leaving it at the first one. I assume I accidentally hit a hotkey or something. Help me fix this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
工具->选项
点击文本编辑器->无论语言 ->格式化
Tools->Options
Click Text Editor -> Whatever language -> Formatting
工具 -> 选项 -> 文本编辑器 -> C#(或任何语言)-> 格式 -> 新行
选择所需的选项。
如果您安装了电源命令,则可以转到“工具” -> 选项 -> 电源命令并确保选择“保存时格式化文档”。
每当您保存编辑后的文件时,大括号都会自动对齐。
Tools->Options->Text Editor->C# (or whatever language)->Formatting->New Lines
Select the options you want.
If you have Power Commands installed you can then go to the Tools->Options->Power Commands and make sure "Format Document on Save" is selected.
Whenever you save the edited file the Curly Braces will be auto aligned.
除了提到的默认 Visual Studio 设置之外,对于 ReSharper 用户,可以通过以下方式进行配置:
ReSharper [菜单]->选项
在“选项”对话框中,导航至“环境”->“环境”。编辑->编辑行为 -> “在右大括号上自动格式化”。查看图片:
In addition to the default Visual Studio settings mentioned, for ReSharper users, this is configured via:
ReSharper [menu] -> Options
In the Options dialog, navigate to Environment -> Editor -> Editor Behavior -> "Auto-format on closing brace". See image:
这个问题十分之九是由文档中其他地方的错误代码引起的。要么是我在一行中缺少
;
,要么是缺少结束}
。 Visual Studio 无法弄清楚我要在代码中写入的内容,因此无法格式化。检查编译器错误并修复它们,然后按Ctrl+K
再按Ctrl + D
使 Visual Studio 重新格式化当前文档(您的热键可能会有所不同,具体取决于版本) Visual Studio 和您的设置)。9 times out of 10 this problem is caused by bad code elsewhere on my document. Either I'm missing a
;
on a line, or perhaps a closing}
. Visual Studio is unable to figure out what I'm trying to write in code and thus it's unable to format. Check for compiler errors, fix them, and then pressCtrl+K
thenCtrl + D
to make Visual Studio reformat the current document (your hotkeys may vary, depending on the version of Visual Studio and your settings).