简体   繁体   English

“保留标签”设置在 Visual Studio 2019 中不起作用

[英]"Keep Tabs" setting not working in Visual Studio 2019

I've been having a problem in Visual Studio 2019 where the program enters tabs as four spaces.我在 Visual Studio 2019 中遇到了一个问题,程序将制表符输入为四个空格。 This is annoying, since I have to hit backspace 4 times to erase an indent, and I need to use arrow keys 4 times to navigate an indent.这很烦人,因为我必须按退格键 4 次才能擦除缩进,而且我需要使用箭头键 4 次来导航缩进。

This used to work fine, but I had to uninstall and re-install Visual Studio to fix another problem (it kept running old versions of my code and wouldn't run the new version), and ever since then, I haven't been able to get it to work.这曾经工作得很好,但我不得不卸载并重新安装 Visual Studio 以解决另一个问题(它一直运行我的代码的旧版本并且不会运行新版本),从那时起,我就再也没有能够让它工作。

I went to settings, and selected 'keep tabs', but it still replaces it with four spaces every time i hit the Tab button.我进入设置,并选择了“保留标签”,但每次我点击标签按钮时它仍然用四个空格替换它。 Interestingly, when I start a new line, I can navigate and backspace normally, but if I enter any more tabs, they are replaced with 4 spaces.有趣的是,当我开始一个新行时,我可以正常导航和退格,但是如果我输入更多选项卡,它们会被替换为 4 个空格。

I've tried looking around, but I can't seem to find anything that addresses my issue.我试过环顾四周,但似乎找不到任何可以解决我的问题的东西。 Can anyone help?任何人都可以帮忙吗?

How to fix problem in Visual Studio with "Keep tabs" not working.如何解决 Visual Studio 中“保留标签”不起作用的问题。

I also had this problem with tabs being converted to spaces.我也遇到了将制表符转换为空格的问题。

I checked Tools>Options>Text Editor> (All languasges as well as c/c++) >Tabs> and assured that "Keep tabs" was selected.我检查了工具>选项>文本编辑器>(所有语言以及c/c++)>标签>并确保选择了“保留标签”。

After some trouble shooting I found that only one file had this problem (file1.h).经过一些故障排除后,我发现只有一个文件有这个问题(file1.h)。

I created a new empty file (file2.h) that worked correctly.我创建了一个可以正常工作的新空文件 (file2.h)。 I took the statements from file1.h and divided them into small block.我从 file1.h 中取出语句并将它们分成小块。 Then I moved the blocks to file2 and after each block I tested file2.然后我将块移动到 file2,在每个块之后我测试了 file2。 After a few block suddenly file2.h failed.几个块后突然file2.h失败。 When I removed the last block from file2 the problem was solved.当我从 file2 中删除最后一个块时,问题就解决了。

My conclusion is, that the source code contained some invivisible code, that made the text editor turn off the "Keep tabs" setting.我的结论是,源代码包含一些不可见的代码,这使得文本编辑器关闭了“保留标签”设置。

I have seen comments about a setting "Use adaptive formatting" that might be relevant.我看到了有关可能相关的设置“使用自适应格式”的评论。 So far I have turned this setting off.到目前为止,我已关闭此设置。

My setup is Visual Studio Community 2019 v 16.4.4 with an Arduino plug in from Visual Micro v 1912 28 2.我的设置是 Visual Studio Community 2019 v 16.4.4,带有来自 Visual Micro v 1912 28 2 的 Arduino 插件。

/Steen /斯蒂恩

Disable the checkbox: Tools->Options->Text Editor->Advanced->Use Adaptive Formatting禁用复选框: Tools->Options->Text Editor->Advanced->Use Adaptive Formatting

You will still need to delete the spaces it inserted for you, but will retain tabs afterwards.您仍然需要删除它为您插入的空格,但之后会保留制表符。

Also note that Visual Studio 2019 now uses and prioritizes .editorconfig files over the Tools -> Options -> Text Editor settings.另请注意,Visual Studio 2019 现在使用.editorconfig文件并将其优先于Tools -> Options -> Text Editor设置。 If you have tried the above answers and still cannot get your indent and tab settings to work, then look for an .editorconfig file anywhere in your project's directory structure.如果您尝试了上述答案,但仍然无法使缩进和制表符设置起作用,请在项目目录结构中的任何位置查找.editorconfig文件。

For instance in my project Angular CLI created one for me when I initialize a new ng project in my .net Web API directory structure.例如,在我的项目中,当我在我的 .net Web API 目录结构中初始化一个新的 ng 项目时,Angular CLI 为我创建了一个。 All my *.ts files were not cooperating.我所有的 *.ts 文件都不合作。

I had to edit the .editorconfig file to look like this in order to get 4 space indent and tab instead of spaces.我必须将.editorconfig文件编辑为如下所示,以便获得 4 个空格缩进和制表符而不是空格。 Once I did that, Ctrl + K + D (reformat) started working again:一旦我这样做了, Ctrl + K + D (重新格式化)再次开始工作:

# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM