Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you auto remove unused imports - Visual Studio Code

I'm using Visual Studio Code to create a game in Unity so I'm programming in C#. I'd like to know how to:

A) Force the editor to remove unused imports when I save. B) Remove all unused imports, project-wide

I see allusions to this snippet when I google around:

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

Neither one does anything for me.

like image 777
Programmer9000 Avatar asked Jan 22 '26 14:01

Programmer9000


1 Answers

This worked for me !

  • Press ctrl+ shift+ P

  • Search settings.json

  • Add the following code

     "editor.codeActionsOnSave": {
      "source.fixAll": true,
      "source.organizeImports": true
    },
    
like image 85
krishnaacharyaa Avatar answered Jan 24 '26 20:01

krishnaacharyaa



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!