如何在 Visual Studio Code 中添加 'Remove unused imports' Python 快捷键
要在 Visual Studio Code 中为 Python 文件添加 Shift-Alt-R 快捷键以删除未使用的导入:
- 按
Ctrl-Shift-P打开命令面板 - 输入
Preferences: Open Keyboard Shortcuts (JSON)并选择它 - 将以下 JSON 添加到打开的 JSON 文件末尾(但在
]字符之前):
keybindings_remove_unused_imports.json
{
"key": "shift+alt+r",
"command": "editor.action.codeAction",
"args": {
"kind": "source.unusedImports",
},
"when": "editorLangId != 'typescript'"
},
{
"key": "shift+alt+r",
"command": "typescript.removeUnusedImports",
"when": "editorLangId == 'typescript'"
}不要忘记在前一个块后添加逗号。
保存文件。
现在你可以按 Shift-Alt-R 删除 Python 文件中未使用的导入。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow