Integrated Development Environments Superpowers 13 exercises
solution

The Organize Imports Hotkey in VS Code

Hitting Shift + Alt + O will run the Organize Imports command, and instantly clean up the imports:


import { MAX_PAGE } from "./dummy-import-2";

This command can also be run from VS Code's Command Pallette, which is opened by hitting Command + Shift + P. Once the Command Pall

Loading solution

Transcript

00:00 Ready for this? We can just go Shift, Alt, O, and bam. All done. What just happened there? Well, if I do something different here, if I go Command, Shift, P, again, I'm on a Mac, and I look for a command, this opens up the command palette in VS Code,

00:19 what I can do is I can find the Organize Imports command, and I can run that. And you can see too that it has command, sorry, it's not command, it's Shift, Alt, O, and then that, like, if you do that key binding, it will run it for you. Or you can do it from the command line too.

00:37 So that's two different options for doing Organize Imports. Organize Imports will prune stuff that's sort of not supposed to be there, so unused variables here. It will also, I think, do a little bit of organization of your imports as well, making sure that if you're importing the same thing from two different import statements, then it will clean that up too.

00:56 It's just a really lovely command to get, just like really autocomplete, just to be able to understand kind of how to clean this stuff up quickly. Because doing this manually, it just feels like a massive pain after you've done this a couple of times. It's just beautiful.