如何在 Visual Studio Code 中添加 'Remove unused imports' Python 快捷键

要在 Visual Studio Code 中为 Python 文件添加 Shift-Alt-R 快捷键以删除未使用的导入:

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 文件中未使用的导入。


Check out similar posts by category: Python, VSCode