VSCodeTips

Tony Hicks
Tony Hicks

Posted on

Automatically organize imports

While refactoring your javascript/typescript code it's easy to remove things but forget to get rid of the unused imports.

Alt Text

In VSCode, you can easily remove these with the shortcut : Shift + Alt + O.
This is sometimes easy to forget to do though, and wouldn't it be better if there was some way to do this automatically every time you save?

In VSCode, go to File -> Preferences -> Settings and click on the icon in the top right hand corner to open up the settings in JSON.

Alt Text

Add the following json:

"editor.codeActionsOnSave": {
    "source.organizeImports": true
},
Enter fullscreen mode Exit fullscreen mode

So that it looks something like the following:
Alt Text

Et voilà!
Your imports will now be organized every time you save a file.
Enjoy :-)

Discussion (0)