VisualStudio: Automatically turn tabs into spaces
It's weird that Google did not bring up an answer to this question:
I am using Visual Studio 1.56.0 (user setup) and would like to configure an editor to input the appropriate number of spaces when I press the tab key, instead of inserting a physical tab character.
I found some discussion on this topic, and the suggestions I found included to use one of:
Tools->Options->Text Editor->All Languages->Tabs
Preferences -> Source Code -> Code Formatting
Edit->Advanced->Set Indentation ->Spaces
None of these solutions work, becaue
-
I don't see a menu called "Tools" (I just have File, Edit, Selection, View, Go, Run, Terminal and Help)
-
I have an item "Preferences" under the "File" Menu, but this in turn does not have an entry called "Source Code".
-
There is no item "Advanced" under the "Edit" menu.
A (for me) logical place to find such an option would be File/Preferences/TextEditor/Formatting, but there is no tabs->space option in that section.
UPDATE, based on the answer given by harrymc :
I understand that Visual Studio Code (what I use) is a different text editor from Visual Studio.
Interestingly, the link to User and Workspace Settings shows a screenshot which looks different from what my Visual Studio Code shows: In the website, Settings should be available for either "User" or "Workspace" (there are two tabs of this name visible in the screenshot on that side), while in my editor, the Settings page shows only "User". However I don't think that this is related to my problem, because when I choose "Commonly Used" in these User-Settings and scroll down, I indeed see a configuration item named Editor: Insert Spaces with the description
Insert Spaces when pressing Tab
This should be exactly the option I was looking for. However, it does have the checkmark set, but my files still get a tab character.
I notice that next to this settings we can find the remark: This setting is overridden based on the file contents when "Editor: Detect Indentation" is on. Indeed, Detect Indentation has a checkmark too, and I unchecked it.
I thought that this should settle it, but it does not. To repeat: I know have
Detect Indentation: unchecked
Insert Spaces: checked
I now created a new file and typed a tab and some other characters, and saved the file. I could see that the new file also has a physical tab in it.
You are using Visual Studio Code and not Visual Studio, which is why the advice you found does not pertain to you.
The post Basic Editing : Indentation says this:
VS Code lets you control text indentation and whether you'd like to use spaces or tab stops. By default, VS Code inserts spaces and uses 4 spaces per Tab key. If you'd like to use another default, you can modify the
editor.insertSpaces
andeditor.tabSize
settings."editor.insertSpaces": true, "editor.tabSize": 4,
Sometimes tabs are not detected when pressed if the following setting is not set:
"editor.detectIndentation": true
For more information, see User and Workspace Settings.