简体   繁体   English

在编写 Python 时在 VSCode 中使用制表符而不是空格?

[英]Use tabs instead of space in VSCode when writing Python?

How does one make the formatter in VSCode use tabs instead of spaces for indentation when programming in Python?在 Python 中编程时,如何使 VSCode 中的格式化程序使用制表符而不是空格进行缩进? I have already set VSCode to use tabs, but the formatter for Python ignores that and just does its own thing.我已经将 VSCode 设置为使用制表符,但是 Python 的格式化程序忽略了这一点,只是做自己的事情。

I've been trying to Google around, but I am only seeing results telling me how to do the opposite, ie.我一直在尝试谷歌,但我只看到结果告诉我如何做相反的事情,即。 spaces instead of tabs, but that is not what I want.空格而不是制表符,但这不是我想要的。 I tried to look at autopep8, which VSCode seems to be using for this formatting, but I can't find anything useful there, either.我试图查看 autopep8,VSCode 似乎正在使用它来进行这种格式化,但我也找不到任何有用的东西。

You can use the editorconfig extension.您可以使用 editorconfig 扩展。

Create a .editorconfig at the root of the project and specify your configuration.在项目的根目录下创建一个.editorconfig并指定您的配置。

root = true

[*] # extensions of the files
indent_style = tab
indent_size = 2

Run format document after that and.. viola!之后运行format document和..中提琴!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM