简体   繁体   English

防止vscode在python文件中输入后自动添加两个空格

[英]Prevent vscode automatic add two space after enter in python file

I am writing python code in vscode, after an expression, each time I hit enter to start a new line, it will automatic add one space for the newline.我在vscode中写python代码,在一个表达式之后,每次我按回车开始新行时,它会自动为换行符添加一个空格。

Instead, what I really want is the starting new line would be aligned with the start of the statement, ie:相反,我真正想要的是起始新行将与语句的开头对齐,即:

def fun():
    arg = 'fake'
    cursor should be aligned with arg

Now what I got is the cursor is one space of the start.现在我得到的是光标是开始的一个空格。 I searched and couldn't find out where to set this, the Tab Size is 4 space.我搜索并找不到设置的位置,选项卡大小为 4 个空格。

I still don't find out the causing issue, but on my project I solved it by setting black path to my absolute path.我仍然没有找出导致问题的原因,但是在我的项目中,我通过将黑色路径设置为我的绝对路径来解决它。 The answers provided below is not the reason why it doesn't work in my vscode.下面提供的答案不是它在我的 vscode 中不起作用的原因。 I attached the pic here.我在这里附上了图片。 My vscode shortcut我的 vscode 快捷方式

使用Ctrl + Shift + P打开命令面板,输入Indent with spaces ,按Enter并选择4

Set also the tab size at the status bar to 4 instead of 2 and you're good to go.还将状态栏上的选项卡大小设置为 4 而不是 2,您就可以开始了。 在此处输入图片说明

Your situation for now:你现在的情况:

在此处输入图片说明

Click Space:2 and select Indent Using Space :单击Space:2并选择Indent Using Space

在此处输入图片说明

Slect 4:选择 4:

在此处输入图片说明

It should be work:它应该是工作:

在此处输入图片说明

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

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