Search code examples
visual-studio-codeformattingpython-black

Black does not support "Format Selection" command


I need to indent my python file in VS Code. I followed the normal procedure:

On Windows Shift + Alt + F
On Mac Shift + Option + F
On Linux Ctrl + Shift + I

But my question is every time when I try to format python file it it says

Black does not support "Format Selection"

So someone can explain what's going wrong here?

My python version is Python 3.7.6.
VS Code details:

Version: 1.46.0 (user setup)
Commit: a5d1cc28bb5da32ec67e86cc50f84c67cc690321
Date: 2020-06-10T09:03:20.462Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0

OS: Windows_NT x64 10.0.18363 

Solution

  • It sounds like your keybindings are set to run "Format Selection" instead of "Format Document"; Black only supports the latter, not the former. If you run the "Format Document" command that should work without issue.