How to setup vscode settings for Python formatter?

Viewed 2410

Somehow my formatter isn't working. I pip installed yapf , but when I do cntr+shift+p -> Format Document or Shift + Alt + F on a selected code, it doesn't change. I heard it autoformattes on save, but that didn't work either.

I am trying to follow the guide here

https://code.visualstudio.com/docs/python/editing#_formatting

It mentions I should edit this part in the settings

"python.formatting.yapfArgs": ["--style", "{based_on_style: chromium, indent_width: 20}"],

But when I search this, this is the only thing I see

https://snipboard.io/9sCB8H.jpg

What I am trying to do at the moment is set the indent to 4 spaces, and also adjust the max line length.

This are what my settings look like for formatting

https://snipboard.io/LXklRI.jpg

1 Answers

It seems in the preference you have not set the correct "provider" for the formatting

enter image description here

You can also check for the file C:\Users\\AppData\Roaming\Code\User\settings.json (if you want to change globally) or \.vscode\settings.json (if you want to change for the current workspace only).

enter image description here

Hope that helps.

Related