Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off automatic deletion of unused imports in VS Code? [duplicate]

VS Code automatically deletes unused imports and even more annoyingly it deletes imports that are used, but commented out. So for example, if I was to save this code:

from pprint import pprint
# pprint("foo")

It would remove the first line. So how can I turn this feature off, because it constantly forces me to rewrite the imports?

like image 662
patrykK1028 Avatar asked Oct 13 '25 11:10

patrykK1028


2 Answers

Check your settings.json (User and Workspace) for the following settings, delete this configuration or change it to false.

    "editor.codeActionsOnSave": {
        "source.fixAll": true,
    },
like image 87
JialeDu Avatar answered Oct 15 '25 06:10

JialeDu


Search for "editor.codeActionsOnSave" in settings. click "Edit in settings.json"

"editor.codeActionsOnSave": {
    "source.organizeImports": "never"
},
like image 29
Shahrier Nafis Avatar answered Oct 15 '25 06:10

Shahrier Nafis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!