简体   繁体   English

如何在 VS Code 中关闭自动删除未使用的导入?

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

VS Code automatically deletes unused imports and even more annoyingly it deletes imports that are used, but commented out. VS Code 会自动删除未使用的导入,更烦人的是它会删除已使用但被注释掉的导入。 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?那么如何关闭此功能,因为它不断迫使我重写导入?

Check your settings.json ( User and Workspace ) for the following settings, delete this configuration or change it to false .检查您的settings.json用户工作区)的以下设置,删除此配置或将其更改为false

    "editor.codeActionsOnSave": {
        "source.fixAll": true,
    },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM