I'm a code purist, preferring my own style of code formatting as opposed to Visual Studio's default settings. I've turned off auto-formatting options in Tools/options. In most cases it works.
我是一个代码纯粹主义者,更喜欢我自己的代码格式,而不是Visual Studio的默认设置。我在工具/选项中关闭了自动格式化选项。在大多数情况下,它有效。
After using any of the built-in refactorings, Visual Studio clobbers my settings with its default settings. How do I keep VS from doing that?
使用任何内置重构后,Visual Studio使用其默认设置破坏我的设置。我如何让VS不这样做?
13 个解决方案
#1
I had this problem while writing VB in an aspx
page.
我在aspx页面编写VB时遇到了这个问题。
The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty Listing' OFF.
解决方案是转到“工具>选项>文本编辑器>基本> VB特定”并将“漂亮列表”关闭。
Note - in Visual Studio 2015 this can be found at:
注意 - 在Visual Studio 2015中,可以在以下位置找到:
Tools > Options > Text Editor > Basic > Advanced
工具>选项>文本编辑器>基本>高级
#2
#3
In my case, it was ReSharper.
就我而言,它是ReSharper。
Test if ReSharper
*: How can I disable ReSharper in Visual Studio and enable it again?
*:如何在Visual Studio中禁用ReSharper并再次启用它?
Prevent ReSharper from reformatting code
*: Is there a way to mark up code to tell ReSharper not to format it?
*:有没有办法标记代码告诉ReSharper不要格式化它?
Update
It was ReSharper in the end:
最后是ReSharper:
#4
In VS2017 you can change it after selecting your coding language in the settings menu. There is an option called "new Lines" in the "Formatting"-submenu.
在VS2017中,您可以在设置菜单中选择编码语言后进行更改。在“格式化”子菜单中有一个名为“新行”的选项。
#5
You might have had Power Tool installed.
您可能安装了Power Tool。
In this case you can turn it off from 'Tools > Options > Productivity Power Tools > PowerCommands > General'
在这种情况下,您可以从“工具”>“选项”>“生产力”工具>“PowerCommands”>“常规”中将其关闭
#6
I doubt that you can disable re-formatting after refactoring. Refactoring changes code and since it's only text I doubt what you'd want is that it just dumps unformatted text into your source. Wouldn't it be a little easier to just set the code style VS adheres to to the style you like and follow?
我怀疑你可以在重构后禁用重新格式化。重构更改代码,因为它只是文本我怀疑你想要的是它只是将未格式化的文本转储到你的源代码中。将代码风格设置为VS遵循您喜欢和遵循的风格会不会更容易一些?
#7
The reformat on semicolon or closing brace cannot be turned off. I find it infuriating the Microsoft would have the temerity to tell anyone how to format code; the most illegible code I have ever seen was while working there.
分号或右括号的重新格式无法关闭。我觉得微软真的会冒昧地告诉任何人如何格式化代码;我见过的最难以辨认的代码是在那里工作。
I want adjacent assignments to be vertically aligned; VS reformats them to one space on either side of the equal sign irrespective of the length of the variable on the left. This is intolerable. And turning it off on the editor options is ignored; given comments like the opener above I am certain this is deliberate.
我希望相邻的作业垂直对齐; VS将它们重新格式化为等号两侧的一个空格,而不管左侧变量的长度。这是不能容忍的。关闭编辑器选项会被忽略;鉴于上面的揭幕战,我确信这是故意的。
Consistency is only a virtue when it leads to desirable outcomes. This is not one.
一致性只是导致理想结果的一种美德。这不是一个。
#8
#9
You can tweak the settings of the code formatting. I always turn off all extra line breaks, and then it works fine for how I format the code.
您可以调整代码格式的设置。我总是关掉所有额外的换行符,然后它可以很好地用于格式化代码。
If you tweak the settings as close as you can to your preference, that should leave you minimal work whenever you use refactoring.
如果您根据自己的喜好尽可能地调整设置,那么每当您使用重构时,这应该会让您的工作量减少。
#10
Follow TOOLS->OPTIONS->Text Editor->CSS->Formatting Choose "Compact Rules" and uncheck "Hiearerchical indentation"
按照工具 - >选项 - >文本编辑器 - > CSS->格式选择“压缩规则”并取消选中“Hiearerchical缩进”
#11
In addition to Tango's answer for the actual solution, there may be people actually want to stay current with auto-formats but not have it screw up your relevant changes. I would suggest that you modify the file to have auto-format activate, check in those changes, then proceed with the actual changes you wish to make.
除了Tango对实际解决方案的回答之外,可能有人真的希望保持最新的自动格式,但不要让它搞砸你的相关变化。我建议您修改文件以激活自动格式,检查这些更改,然后继续进行您想要进行的实际更改。
That way your code can stay up to date, but your check in will be relevant.
这样您的代码可以保持最新,但您的签入将是相关的。
#12
VS2015 settings that helped me prevent auto formatting:
VS2015设置帮助我防止自动格式化:
(and Tools > Options > Text Editor > Basic > Advanced, just like Tango91 suggested)
(和工具>选项>文本编辑器>基本>高级,就像Tango91建议的那样)
#13
Try disabling the extension Bundler & Minifier
尝试禁用扩展Bundler和Minifier
#1
I had this problem while writing VB in an aspx
page.
我在aspx页面编写VB时遇到了这个问题。
The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty Listing' OFF.
解决方案是转到“工具>选项>文本编辑器>基本> VB特定”并将“漂亮列表”关闭。
Note - in Visual Studio 2015 this can be found at:
注意 - 在Visual Studio 2015中,可以在以下位置找到:
Tools > Options > Text Editor > Basic > Advanced
工具>选项>文本编辑器>基本>高级
#2
Disable pretty listing. It is the option that re-formats what you are doing. I had the same discomfort with it and after doing it, my code stays how i want and it doesn't go back to previous settings.
禁用漂亮的列表。这是重新格式化您正在做的事情的选项。我对它有同样的不适,经过这样做,我的代码保持我想要的方式,它不会回到以前的设置。
#3
In my case, it was ReSharper.
就我而言,它是ReSharper。
Test if ReSharper
*: How can I disable ReSharper in Visual Studio and enable it again?
*:如何在Visual Studio中禁用ReSharper并再次启用它?
Prevent ReSharper from reformatting code
*: Is there a way to mark up code to tell ReSharper not to format it?
*:有没有办法标记代码告诉ReSharper不要格式化它?
Update
It was ReSharper in the end:
最后是ReSharper:
#4
In VS2017 you can change it after selecting your coding language in the settings menu. There is an option called "new Lines" in the "Formatting"-submenu.
在VS2017中,您可以在设置菜单中选择编码语言后进行更改。在“格式化”子菜单中有一个名为“新行”的选项。
#5
You might have had Power Tool installed.
您可能安装了Power Tool。
In this case you can turn it off from 'Tools > Options > Productivity Power Tools > PowerCommands > General'
在这种情况下,您可以从“工具”>“选项”>“生产力”工具>“PowerCommands”>“常规”中将其关闭
#6
I doubt that you can disable re-formatting after refactoring. Refactoring changes code and since it's only text I doubt what you'd want is that it just dumps unformatted text into your source. Wouldn't it be a little easier to just set the code style VS adheres to to the style you like and follow?
我怀疑你可以在重构后禁用重新格式化。重构更改代码,因为它只是文本我怀疑你想要的是它只是将未格式化的文本转储到你的源代码中。将代码风格设置为VS遵循您喜欢和遵循的风格会不会更容易一些?
#7
The reformat on semicolon or closing brace cannot be turned off. I find it infuriating the Microsoft would have the temerity to tell anyone how to format code; the most illegible code I have ever seen was while working there.
分号或右括号的重新格式无法关闭。我觉得微软真的会冒昧地告诉任何人如何格式化代码;我见过的最难以辨认的代码是在那里工作。
I want adjacent assignments to be vertically aligned; VS reformats them to one space on either side of the equal sign irrespective of the length of the variable on the left. This is intolerable. And turning it off on the editor options is ignored; given comments like the opener above I am certain this is deliberate.
我希望相邻的作业垂直对齐; VS将它们重新格式化为等号两侧的一个空格,而不管左侧变量的长度。这是不能容忍的。关闭编辑器选项会被忽略;鉴于上面的揭幕战,我确信这是故意的。
Consistency is only a virtue when it leads to desirable outcomes. This is not one.
一致性只是导致理想结果的一种美德。这不是一个。
#8
As suggest by @TheMatrixRecoder took a bit of finding for me so maybe this will help someone else.
正如@TheMatrixRecoder的建议为我找了一点,所以也许这会帮助别人。
Unitick these options to prevent annoying automated formatting when you places a semicolon or hit return at the end of a line.
单击这些选项以防止在分号行放置分号或点击返回时恼人的自动格式化。
#9
You can tweak the settings of the code formatting. I always turn off all extra line breaks, and then it works fine for how I format the code.
您可以调整代码格式的设置。我总是关掉所有额外的换行符,然后它可以很好地用于格式化代码。
If you tweak the settings as close as you can to your preference, that should leave you minimal work whenever you use refactoring.
如果您根据自己的喜好尽可能地调整设置,那么每当您使用重构时,这应该会让您的工作量减少。
#10
Follow TOOLS->OPTIONS->Text Editor->CSS->Formatting Choose "Compact Rules" and uncheck "Hiearerchical indentation"
按照工具 - >选项 - >文本编辑器 - > CSS->格式选择“压缩规则”并取消选中“Hiearerchical缩进”
#11
In addition to Tango's answer for the actual solution, there may be people actually want to stay current with auto-formats but not have it screw up your relevant changes. I would suggest that you modify the file to have auto-format activate, check in those changes, then proceed with the actual changes you wish to make.
除了Tango对实际解决方案的回答之外,可能有人真的希望保持最新的自动格式,但不要让它搞砸你的相关变化。我建议您修改文件以激活自动格式,检查这些更改,然后继续进行您想要进行的实际更改。
That way your code can stay up to date, but your check in will be relevant.
这样您的代码可以保持最新,但您的签入将是相关的。
#12
VS2015 settings that helped me prevent auto formatting:
VS2015设置帮助我防止自动格式化:
(and Tools > Options > Text Editor > Basic > Advanced, just like Tango91 suggested)
(和工具>选项>文本编辑器>基本>高级,就像Tango91建议的那样)
#13
Try disabling the extension Bundler & Minifier
尝试禁用扩展Bundler和Minifier