如何在 Visual Studio Code 中自动缩进 Python 代码? [英] How do I auto-indent Python code in Visual Studio Code?

查看:113
本文介绍了如何在 Visual Studio Code 中自动缩进 Python 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 上使用 Visual Studio Code(不是 Visual Studio),但似乎无法找到如何为 Python 启用自动缩进.我查看了所有偏好,在 Google 上花了一些时间,但找不到任何内容.

I'm using Visual Studio Code (not Visual Studio) on Linux and I can't seem to find out how to turn on auto-indentation for Python. I've looked all over preferences, spent some time on Google, and can't find anything.

有人知道怎么做吗?

推荐答案

在 VS Code 中你可以在几个地方设置缩进:

In VS Code you can set the indentation in several places :

  • 常规/工作区设置(底部栏),
  • 用户设置,
  • 语言格式化程序设置.

使用 Python 时,无论您设置什么设置,所有设置都会被 autopep8 语言格式化程序设置的 autopep8Args 值覆盖,该设置的缩进大小为4.

When using Python, no matter what settings you set, all of them are overridden by the autopep8Args value of the autopep8 language formatter setting, which has an indent size of 4.

默认情况下,autopep8 用作 VS Code Python 格式化程序,但还有其他格式,例如 yapf.

By default, autopep8 is used as VS Code Python formatter, but there are others, like yapf.

要更新此格式化程序的缩进大小,请在您的用户设置中搜索python.formatting.autopep8Args"并将其设置为:["--indent-size=2"],

To update the indent size of this formatter, search in your user settings the "python.formatting.autopep8Args" and set it to : ["--indent-size=2"],

"python.formatting.autopep8Args": ["--indent-size=2"],

这篇关于如何在 Visual Studio Code 中自动缩进 Python 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆