【发布时间】:2019-10-01 11:58:46
【问题描述】:
我想在 Python 的 Visual Studio Code(版本 1.38.1)中使用 2 个空格进行缩进(其他语言也是如此,但现在是 Python)。但是,当自动格式化(保存和使用 Shift Alt F)时,它会将其更改为 4 个空格。
我已将其设置为使用 2 个空格,我可以在我的设置和 bottom right hand corner.
这是我的设置:
{
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 2,
"editor.formatOnPaste": true,
"window.zoomLevel": 0,
"workbench.colorTheme": "Visual Studio Light",
"editor.codeLens": false,
"editor.formatOnType": true,
"editor.formatOnSave": true
}
我也更新了 config.py 文件
prefs['indent_size'] = 2
我有 3 个扩展,Python、C# 和 yo。
我已经在互联网上搜寻无济于事,任何帮助将不胜感激!
【问题讨论】:
-
您将程序设置为使用制表符而不是空格缩进。这就是为什么您的更改不起作用的原因。尝试单击
Tab size: 2并选择Indent Using Spaces。这行得通吗? -
你在使用 Python 扩展吗?如果是的话,你设置了什么格式化程序?
-
@HampusLarsson 不,它不起作用:(
-
@BrettCannon 我正在为 Visual Studio Code 使用 Python 扩展。我不记得设置了格式化程序,你知道我可以在哪里检查吗?
-
@bardr Python 扩展在没有你设置的情况下不提供格式(除非 VS Code 神奇地使用
"editor.formatOnType"以某种方式应用于整个文件,在这种情况下它不使用 " editor.tabSize"。您可以通过查看工作区中的.vscode/settings.json文件或在 VS Code 中打开您的设置来检查您的设置。(并且config.py与 VS Code 的 Python 扩展无关,所以我不是确定这是什么意思。)
标签: python visual-studio-code formatting indentation