在 Visual Studio 中关闭自动格式化

发布于 2024-07-16 11:45:48 字数 160 浏览 4 评论 0原文

我更喜欢我自己的代码格式设置,而不是 Visual Studio 的默认设置。 我已经在“工具”→“选项”中关闭了自动格式化选项。 在大多数情况下,它是有效的。

但是,在使用任何内置重构后,Visual Studio 会使用其默认设置破坏我的设置。 我如何防止 VS 这样做?

I prefer 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.

However, 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

囍孤女 2024-07-23 11:45:48

我在 aspx 页面中编写 VB 时遇到了这个问题。

解决方案是转到“工具>” 选项> 文本编辑器> 基本> VB Specific”并关闭“Pretty Listing”。


注意 - 在 Visual Studio 2015 中,可以在以下位置找到:

工具 > 选项> 文本编辑器> 基本> 先进的

I had this problem while writing VB in an aspx page.

The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty Listing' OFF.


Note - in Visual Studio 2015 this can be found at:

Tools > Options > Text Editor > Basic > Advanced

城歌 2024-07-23 11:45:48

禁用漂亮列表。 该选项可以重新格式化您正在做的事情。 我对此也有同样的不适,完成之后,我的代码保持我想要的方式,并且不会返回到以前的设置。

输入图像描述这里

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.

enter image description here

狼性发作 2024-07-23 11:45:48

正如 @TheMatrixRecoder 的建议,我做了一些发现,所以也许这会对其他人有所帮助。

单独勾选这些选项可以防止在行尾放置分号或按回车键时出现烦人的自动格式化。

As suggest by @TheMatrixRecoder took a bit of finding for me so maybe this will help someone else.
VS 2017 option can be found here

Unitick these options to prevent annoying automated formatting when you places a semicolon or hit return at the end of a line.

〆一缕阳光ご 2024-07-23 11:45:48

就我而言,它是 ReSharper。

测试 ReSharper

StackOverflow:我该如何在 Visual Studio 中禁用 ReSharper 并再次启用它?

阻止 ReSharper 重新格式化代码

StackOverflow:有没有办法标记代码来告诉ReSharper不要格式化它?

更新2017-03-01

这是ReSharper结束:

在此处输入图像描述

更新 2020-12-18

在最新版本的 ReSharper 上,有更多选项:取消选中此页面上的所有内容,并确保所有下拉菜单都设置为相当于 None.

ReSharper“打字辅助”就像一个 3 岁的孩子试图“帮助”建造一座卡片城堡。 一个简单的退格键或回车键将(很差地)重新格式化整个代码块,需要将其撤消或痛苦地格式化回原始状态。

如果这还不够的话,这会增加打字时的延迟,所以有时感觉就像尝试穿着滑雪板跑步一样。

In my case, it was ReSharper.

Test if ReSharper

StackOverflow: How can I disable ReSharper in Visual Studio and enable it again?

Prevent ReSharper from reformatting code

StackOverflow: Is there a way to mark up code to tell ReSharper not to format it?

Update 2017-03-01

It was ReSharper in the end:

enter image description here

Update 2020-12-18

On the latest version of ReSharper, there are more options: untick everything on this page, and ensure all dropdowns are set to the equivalent of None.

ReSharper "typing assist" is like a 3-year-old trying to "help" build a card castle. A simple backspace or an enter key will (poorly) reformat entire blocks of code, requiring it to be undone or painfully formatted back to the original.

And if that is not enough, this is the bit that adds delays when typing so sometimes it feels like trying to run in skis.

甜味超标? 2024-07-23 11:45:48

您可能已经安装了Power Tool

在这种情况下,您可以从“工具>”将其关闭。 选项> 生产力电动工具> 电源命令> 常规'

enter图片描述在这里

You might have had Power Tool installed.

In this case you can turn it off from 'Tools > Options > Productivity Power Tools > PowerCommands > General'

enter image description here

我不在是我 2024-07-23 11:45:48

无法关闭分号或右大括号的重新格式化。 我发现微软竟然如此鲁莽地告诉任何人如何格式化代码,这令人愤怒; 我见过的最难以辨认的代码是在那里工作的时候。

我希望相邻的作业垂直对齐; VS 将它们重新格式化为等号两侧各一个空格,无论左侧变量的长度如何。 这是无法容忍的。 并且在编辑器选项中关闭它会被忽略; 鉴于像上面的开场白这样的评论,我确信这是故意的。

只有当一致性能带来理想的结果时,它才是一种美德。 这不是一个。

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.

Consistency is only a virtue when it leads to desirable outcomes. This is not one.

羁〃客ぐ 2024-07-23 11:45:48

帮助我防止自动格式化的VS2015设置:(

以及工具>选项>文本编辑器>基本>高级,就像建议使用 Tango91)

在此处输入图像描述

VS2015 settings that helped me prevent auto formatting:

(and Tools > Options > Text Editor > Basic > Advanced, just like Tango91 suggested)

enter image description here

人疚 2024-07-23 11:45:48

在 VS2017 中,您可以在设置菜单中选择编码语言后更改它。 “格式”子菜单中有一个名为“新行”的选项。

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.

魄砕の薆 2024-07-23 11:45:48

我看到这里的许多答案都解决了特定情况的问题。

对于我的情况,我不断发现 IDE 会自动格式化 ASP 页面中的 JavaScript 代码。

要禁用,我取消选中此框:
输入图片此处描述

此外,我发现使用工具栏中的搜索查询 (CTRL+Q) 并仅搜索文本粘贴格式非常有帮助代码>. 正如您通过滚动条看到的,有很多选项需要检查!

输入图片此处描述

I see that many answers here solve the problem for a specific situation.

For my situation I continually found that the IDE would automatically format JavaScript code within an ASP page.

To disable, I unchecked this box:
enter image description here

In addition, I found it very helpful to use the search query in the toolbar (CTRL+Q) and just search for the text format on paste. As you can see with the scroll bar, there are quite a few options to check!

enter image description here

兔姬 2024-07-23 11:45:48

我怀疑您是否可以在重构后禁用重新格式化。 重构会更改代码,因为它只是文本,我怀疑您想要的只是将未格式化的文本转储到源中。 将 VS 遵循的代码风格设置为您喜欢并遵循的风格不是更容易一点吗?

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?

不…忘初心 2024-07-23 11:45:48

按照工具->选项->文本编辑器->CSS->格式
选择“紧凑规则”并取消选中“分层缩进”

Follow TOOLS->OPTIONS->Text Editor->CSS->Formatting
Choose "Compact Rules" and uncheck "Hiearerchical indentation"

哽咽笑 2024-07-23 11:45:48

Clang 格式可能就是这种情况。
以前,整个文件会在文件保存时自动格式化,这让我抓狂(对于未启用 Clang 格式的存储库)。

将“工具 -> 选项 -> LLVM/Clang -> ClangFormat -> Format On Save -> Enable”设置为 False 后,这种行为就消失了。

It can be the case of Clang Format.
Previously, the entire file is automatically formatted on file save, and it drove me nuts (for the repositories which Clang Format is not enabled).

Such behavior is gone after turning "Tools -> Option -> LLVM/Clang -> ClangFormat -> Format On Save -> Enable" to False.

ClangFormat Format On Save

栀子花开つ 2024-07-23 11:45:48

每当我在 Visual Studio 2015、2017 中将任何内容粘贴到 cshtml 文件中时,我都会很生气。我尝试了不同的设置,终于找到了正确的设置:
选项=> 文本编辑器 => HTML=> 高级 => 粘贴(粘贴格式)=> 错误的
输入图片此处描述

I was pissed off every time I pasted anything in cshtml file in Visual Studio 2015, 2017. I tried different settings and finally found the proper one:
Options => Text Editor => HTML => Advanced => Paste (Format on paste) => False
enter image description here

丿*梦醉红颜 2024-07-23 11:45:48

对于 ASP.NET / VB、Visual Studio 2022,混合 VB/html 的自动格式化在 VS 中效果不佳,缩进级别经常出现明显错误,并且与周围的代码不匹配。 这是一个很难找到的设置,但在这里可以禁用它 - 取消选中“漂亮列表”

在此处输入图像描述

For ASP.NET / VB, Visual Studio 2022, the auto formatting of mixed VB/html works poorly in VS, with the indentation level frequently plain wrong and mismatching the code around it. It is a difficult to find setting, but here is where to disable it - uncheck "Pretty listing"

enter image description here

凯凯我们等你回来 2024-07-23 11:45:48

您可以调整代码格式的设置。 我总是关闭所有额外的换行符,然后它就可以很好地适应我格式化代码的方式。

如果您将设置调整为尽可能接近您的偏好,那么每当您使用重构时,您的工作量都会减少。

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.

萌无敌 2024-07-23 11:45:48

除了 Tango 对实际解决方案的回答之外,可能有人实际上希望保持自动格式的最新状态,但又不想让它搞砸您的相关更改。 我建议您修改文件以激活自动格式,签入这些更改,然后继续进行您想要进行的实际更改。

这样您的代码就可以保持最新,但您的签入也将是相关的。

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.

That way your code can stay up to date, but your check in will be relevant.

蓝戈者 2024-07-23 11:45:48

您可能需要检查“工具”->“ 选项-> Xaml 样式器 -> 保存时格式化 xaml

在此处输入图像描述

You might need to check on Tools-> Options-> Xaml Styler -> Format xaml on save

enter image description here

放飞的风筝 2024-07-23 11:45:48

在顶部的导航选项中,选择“工具”,然后选择“管理扩展”。

我安装了 CodeMaid、Visual Assist 和 Rosalyn。 似乎更新开始导致这些自动格式化问题。 我禁用了它们并修复了它。

On the navigation options at the top select "Tools" and then select "Manage Extensions".

I had CodeMaid, Visual Assist, and Rosalyn installed. Seems like an update start to cause these auto formatting issues. I disabled them and do this fixed it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文