Search code examples
pythonvisual-studio-codeformatting

How to setup vscode settings for Python formatter?


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

I am trying to follow the guide here. 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

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

This is what my settings look like for formatting


Solution

  • 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.