How to add 'Remove unused imports' Python keybinding in Visual Studio Code
In order to add the Shift-Alt-R
keybinding for removing unused imports in Python files in Visual Studio Code:
- Press
Ctrl-Shift-P
to open the command palette - Type
Preferences: Open Keyboard Shortcuts (JSON)
and select it - Add the following JSON to the end of the JSON file that opens (but before the
]
character):
{
"key": "shift+alt+r",
"command": "editor.action.codeAction",
"args": {
"kind": "source.unusedImports",
}
}
Don’t forget to add a comma after the previous block.
Save the file.
Now you can press Shift-Alt-R
to remove unused imports in Python files.