VSCode如何更改Python的缩进格式

huangapple go评论74阅读模式
英文:

VSCode how to change indentation format for Python

问题

这段文字的翻译如下:

"The code was copy-pasted from outside. I would like to see if I can format this with <indentation with tab size 2>, but my VSCode doesn't want to do that. It draws the lines for the tab size 2 indentation, but doesn't actually format the code in that manner.

On the other hand, somehow it does good job with JS files, but just not with Python files. I'm using autopep8. Is it because I am using autopep8 and autopep8 doesn't let me change indentation easily?

Thanks!"

英文:

VSCode如何更改Python的缩进格式

The code was copy-pasted from outside. I would like to see if I can format this with <indentation with tab size 2>, but my VSCode doesn't want to do that. It draws the lines for the tab size 2 indentation, but doesn't actually format the code in that manner.

On the other hand, somehow it does good job with JS files, but just not with Python files. I'm using autopep8. Is it because I am using autopep8 and autopep8 doesn't let me change indentation easily?

Thanks!

答案1

得分: 0

Python 无法自动格式化,因为逻辑依赖于缩进

  • 选择第2行的 def 前面的4个空格
  • 使用 Ctrl+D 直到达到 return 前面
  • 输入:Space Space
  • 退出多光标模式:Esc
英文:

Python can't be auto formatted because the logic is indentation dependent

  • select the 4 spaces before the def on line 2
  • use Ctrl+D as many times until you reach before return
  • type: Space Space
  • exit Multi Cursor: Esc

答案2

得分: 0

看起来你已将制表符大小设置为2个空格,如果你希望每行的缩进为一个制表符(2个空格):

  1. 选择要删除缩进的行
  2. 按下Ctrl+[

如果你想要添加缩进,使用Ctrl+]Tab

英文:

It looks like you have set tabsze to 2 spaces, if you want the indentation of each line to be one tab (2 spaces):

  1. Select the lines you want to remove indentation
  2. press <kbd>Ctrl</kbd>+<kbd>[</kbd>

Also if you want to add indentation, use <kbd>Ctrl</kbd>+<kbd>]</kbd> or <kbd>Tab</kbd>

huangapple
  • 本文由 发表于 2023年7月14日 09:03:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76684109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定