简体   繁体   English

Visual Studio 2022 关闭自动缩进

[英]Visual Studio 2022 turn off auto indenting

So i upgraded to VS 2022. and anytime i add a semicolon.所以我升级到 VS 2022。我随时添加分号。 the whole code block gets backtabbed.整个代码块被回退。 does anyone know how to turn this off?有谁知道如何关闭它? getting tired of hitting ctrl z repeatedly..厌倦了反复按 ctrl z ..

Before.前。

分号前

After

在此处输入图像描述

  1. Go to VS2022 Tools - Options Menu Go 到 VS2022 工具 - 选项菜单
  2. Type indent in search在搜索中键入缩进
  3. Look for Indentation under formatting option which appears under在出现在下面的格式选项下查找缩进

Text Editor - C# - Code Style - Formatting Indentation文本编辑器 - C# - 代码样式 - 格式化缩进

check / uncheck boxes to see how your code will look and save when happy选中/取消选中复选框以查看您的代码在高兴时的外观和保存方式

After consolidating code blocks to one block on the razor page... this seems to have corrected the issue.在 razor 页面上将代码块合并为一个块之后......这似乎已经纠正了这个问题。 the indenting I believe may have been caused by some bug where the indenting fails due to attempting to address other formatted code.我认为缩进可能是由于尝试处理其他格式化代码而导致缩进失败的一些错误引起的。 this is not really a solid answer but i did find that moving things around prevented this from occuring and this was nothing to do with any indenting settings within the tools text editor options.这不是一个真正可靠的答案,但我确实发现移动东西可以防止这种情况发生,这与工具文本编辑器选项中的任何缩进设置无关。

I'm not sure if you ever found the correct answer to your question, but I was having the same problem, and reading the other two answers led me to figuring it out.我不确定你是否找到了问题的正确答案,但我遇到了同样的问题,阅读其他两个答案让我弄清楚了。 The problem is with the adaptive formatting option being turned on.问题在于启用了自适应格式选项。 To turn it off, go to要关闭它,go 到

Tools -> Options -> Text Editor -> Advanced工具 -> 选项 -> 文本编辑器 -> 高级

You should see你应该看到在此处输入图像描述

Uncheck 'Use adaptive formatting'取消选中“使用自适应格式”

Save, and restart Visual Studio保存并重新启动 Visual Studio

This should do the trick for you.应该为您解决问题。

There is another option under Tools - Options工具 - 选项下还有另一个选项

Text Editor - All Languages - Tabs.文本编辑器 - 所有语言 - 选项卡。

Try to specify Tab size and indent size尝试指定制表符大小和缩进大小

I believe it is a bug or a new "feature".我相信这是一个错误或一个新的“功能”。 Mine works in VS2019, but worked better in previous versions.我的在 VS2019 中工作,但在以前的版本中工作得更好。 Each new version becomes harder to maintain the indentions that I prefer.每个新版本都变得更难维护我喜欢的缩进。 It is not language dependent either as I also work in VB and it happens there as well.它也不依赖于语言,因为我也在 VB 中工作,它也发生在那里。

For example, in both languages, my personal preference is to add a comment and then indent the code following the comment.例如,在这两种语言中,我个人的偏好是添加注释,然后在注释后面缩进代码。 I have been doing code this way for two decades...my eye flows down the page seeing the flow and code much easier and faster.二十年来,我一直在以这种方式编写代码……我的眼睛顺着页面向下流动,看到流程和代码变得更加轻松快捷。

BUT...in VS2022, every time I indent a code block, the moment I hit enter, my indentions all move to the left, aligned with the comment....so aggravating.但是......在VS2022中,每次我缩进一个代码块时,当我按下回车键时,我的缩进都向左移动,与注释对齐......所以加重了。 Then I have to ctrl-z to make it go back.然后我必须按 ctrl-z 使它 go 回来。 Of course, it goes back only until the next line.当然,它只会返回到下一行。 And often it will reformat the entire function and align everything, all code, all comments, etc.通常它会重新格式化整个 function 并对齐所有内容、所有代码、所有注释等。

All I desire is for it to leave the indentations where I placed them.我只希望它留下我放置它们的凹痕。 So far in VS2022, I have not found how to do this.到目前为止,在 VS2022 中,我还没有找到如何做到这一点。 Hoping someone finds an answer to this.希望有人能找到这个问题的答案。 I will be watchign and thanks in advance!我会注意并提前感谢!

Welcome to the new and improved (super buggy) VS 2022 cshtml page editing experience.欢迎来到新的和改进的(超级错误)VS 2022 cshtml 页面编辑体验。 Click Help -> Send feedback -> Report a problem and tell 'em about it.单击Help -> Send feedback -> Report a problem并告诉他们。

In visual studio 2022 community:在 visual studio 2022 社区中:

  • Go to Tools -> Options -> "Generate.editorconfig file from settings" Go 工具 -> 选项 -> “从设置生成.editorconfig文件”
  • Open.editorconfig in some text editor Open.editorconfig 在一些文本编辑器中
  • Search for "indent_size" and "indent_style" and adapt them to your needs搜索“indent_size”和“indent_style”并根据您的需要进行调整

effects are reflected without even restarting visual studio甚至无需重新启动 visual studio 即可反映效果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2022 关闭灰色建议 - Visual Studio 2022 turn off grey suggestions 如何在 Visual Studio 中关闭括号/引号自动完成 - How to turn off brackets/quotes auto-completion in Visual Studio 如何暂时关闭Visual Studio 2010中的自动格式化 - Howto temporarily turn off auto formating in Visual Studio 2010 避免在Visual Studio中自动生成名称空间。 如何关闭“使用系统”的自动插入 - Avoid auto generated namespace in Visual Studio. How to turn off automatic insertion of “using System;” 在 Visual Studio 201x 中关闭 #region 的自动格式化 - Turn off auto-formatting for a #region in Visual Studio 201x MAC上Visual Studio中的文件缩进 - File indenting in Visual Studio on the MAC Visual Studio 2022 如何仅在选项卡上自动完成? - Visual studio 2022 how to auto complete only on tab? 在ASP.Net MVC视图中防止Visual Studio自动缩进C#代码 - Prevent visual studio auto-indenting C# code in ASP.Net MVC Views 如何在Visual Studio for Mac中关闭“警告错误提示” - how to turn off “warning treaded as error” in visual studio for mac 如何在可移动驱动器上的Visual Studio中关闭对.sln文件的加密? - How to turn off encrypting of .sln files in Visual Studio on removable drive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM