Allen Huang
Allen Huang

Reputation: 105

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.

Instead, what I really want is the starting new line would be aligned with the start of the statement, i.e:

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.

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. I attached the pic here.My vscode shortcut

Upvotes: 3

Views: 6471

Answers (4)

jjj
jjj

Reputation: 81

the problem was 'python indent' extension that I installed. I deleted and it worked

Upvotes: 8

Steven-MSFT
Steven-MSFT

Reputation: 8421

Your situation for now:

enter image description here

Click Space:2 and select Indent Using Space:

enter image description here

Slect 4:

enter image description here

It should be work:

enter image description here

Upvotes: 0

enaielei
enaielei

Reputation: 83

Set also the tab size at the status bar to 4 instead of 2 and you're good to go. enter image description here

Upvotes: 0

RobBlanchard
RobBlanchard

Reputation: 905

Open the command palette with Ctrl+Shift+P, type in Indent with spaces, press Enter and select 4.

Upvotes: 1

Related Questions