英文:
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!"
英文:
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 beforereturn
- type:
Space
Space
- exit Multi Cursor:
Esc
答案2
得分: 0
看起来你已将制表符大小设置为2个空格,如果你希望每行的缩进为一个制表符(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):
- Select the lines you want to remove indentation
- press <kbd>Ctrl</kbd>+<kbd>[</kbd>
Also if you want to add indentation, use <kbd>Ctrl</kbd>+<kbd>]</kbd> or <kbd>Tab</kbd>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论