简体   繁体   中英

"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. 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.

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.

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.

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.

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.

After some trouble shooting I found that only one file had this problem (file1.h).

I created a new empty file (file2.h) that worked correctly. I took the statements from file1.h and divided them into small block. Then I moved the blocks to file2 and after each block I tested file2. After a few block suddenly file2.h failed. When I removed the last block from file2 the problem was solved.

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.

/Steen

Disable the checkbox: 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. 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.

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. All my *.ts files were not cooperating.

I had to edit the .editorconfig file to look like this in order to get 4 space indent and tab instead of spaces. Once I did that, Ctrl + K + D (reformat) started working again:

# 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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