python - 黑色不支持 "Format Selection"命令 - VS Code 错误

标签 python visual-studio-code formatting vscode-settings python-black

我需要在 Vs Code 中缩进我的 python 文件。我按照正常程序,

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


但我的问题是每次我尝试格式化 python 文件时它都会说

Black does not support "Format Selection"



所以有人可以解释这里出了什么问题?
我的python版本是Python 3.7.6
VS代码细节:
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 

最佳答案

在我的情况下(在 VS 代码设置中选择 black 作为 Python 格式化提供程序),我遇到了此警告 每次我将一些文本粘贴到编辑器中时 .
以及VS Code的官方文档has a solution专门为它:

When using the black formatter, VS Code issues the following warning when pasting source code into the editor: Black does not support the "Format Select" command.

To prevent this warning, add the following entry to your user or workspace settings to disable format on paste for Python files:

"[python]": {
    "editor.formatOnPaste": false
}

关于python - 黑色不支持 "Format Selection"命令 - VS Code 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62427817/

相关文章:

使用 BitTorrent-bencode 5.0.8.1 的 Python Bencoding

c# - 将参数从 C# 传递到 Python

python - python aiohttp.web 中间件如何工作

python - 我正在尝试创建一个倒计时器,但它不起作用

asp.net - 格式化 DevExpress ASPxGridView 中的列?

visual-studio-code - 如何忽略拼写检查器中的 Lorem Ipsum 文本?

visual-studio-code - Visual Studio 代码抑制 pep8 警告

c# - Linux 中的 Visual Studio Code - 将 F5(调试)从 "dotnet build"重新映射到 "msbuild csproj"?

mysql - 如何使用 str_to_date (MySQL) 正确解析两位数年份

xslt - XSLT 中的正斜杠有什么用?