【问题标题】:Visual Studio Code indentation tab size of 2 spaces ignored on format (in Python)格式上忽略了 2 个空格的 Visual Studio Code 缩进制表符大小(在 Python 中)
【发布时间】: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


【解决方案1】:

据我所知,Python 扩展支持的格式化程序都没有读取 VS Code 的格式化设置。您需要直接配置格式化程序以使其保持 2 个空格缩进(因格式化程序而异,包括如果您选择黑色甚至无法配置)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 2016-08-17
    • 2013-07-05
    相关资源
    最近更新 更多