1

I'm writing python scripts in VS Code. In the settings the tab size is set to 2, tabs are replaced with spaces.

If I write a smple code snippet with tab size 2, and format the document, the tab size will be formatted to 4. It does not matter if the detect indentation is on or off.

Does anybody know how to solve this problem?

After formatting: picture

Edit: I think, I have to set the autopop8 settings. But I cannot find the settings

trophi20
  • 19
  • 1
  • 5
  • Tab size needn't be the same size as indentation size – psmears Mar 18 '22 at 13:41
  • @psmears but the shown width is 4 and also 4 spaces are included. – trophi20 Mar 18 '22 at 13:50
  • I think, I have to set the autopop8 settings. But I cannot find the settings – trophi20 Mar 18 '22 at 14:31
  • Does this answer your question? [How do I Change VSCode To Indent 4 Spaces Instead Of Default 2?](https://stackoverflow.com/questions/49167053/how-do-i-change-vscode-to-indent-4-spaces-instead-of-default-2) – LSeu Mar 18 '22 at 14:48

1 Answers1

0

You can 1) add the following code in the settings.json file or 2) use the settings interface, which updates settings.json automatically. The quotes preceding each code block are from VSCode's documentation.

The number of spaces a tab is equal to. This setting is overridden // based on the file contents when editor.detectIndentation is true.

"editor.tabSize": 4,

Insert spaces when pressing Tab. This setting is overridden based on the file contents when editor.detectIndentation is true.

"editor.insertSpaces": true,

When opening a file, editor.tabSize and editor.insertSpaces will be detected based on the file contents. Set to false to keep the values you've explicitly set, above.

"editor.detectIndentation": false`
iff_or
  • 880
  • 1
  • 11
  • 24
MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13