Visual Studio Code for Python Developers Transcripts
Chapter: Exploring the Editor
Lecture: Command Palette

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of the most powerful components of Visual Studio Code is what is called the command palette.
0:06 It allows you to access and execute various commands within Visual Studio Code.
0:11 It's a versatile feature that provides a quick and efficient way to execute commands,
0:15 which range from basic editor operations to advanced features and even extensions. You can open up the command palette using a keyboard shortcut,
0:24 such as Ctrl-Shift-P on Windows and Linux or Command-Shift-P on Mac.
0:30 Another way you can open up the command palette is by going to the View menu and clicking on Command Palette.
0:36 Once the command palette is open, you can start typing to search for a specific command or feature that you want to perform.
0:43 As you type, the command palette will dynamically update and filter those results, displaying any relevant commands or suggestions to you.
0:51 So, what can we do here? In order to execute a command from the command palette, you just select it from the filtered list and press Enter.
1:00 Or you can click on it if you'd like. So, as an example, let's say we want to close the current file that we have open. Say Close Editor.
1:08 And what's nice about this is it also shows you any keyboard shortcuts that are associated with that command
1:16 so that you can, over time, learn to memorize that particular keyboard shortcut
1:20 instead of having to go through the command palette for that particular action. In this case, I'll hit Enter or I'll click on that one.
1:27 And it did indeed close the API. If I bring up the command palette again, now I want to open a file. I hit Enter on that file. And I can choose API.py.
1:43 What I find to be really great about the command palette is that even if I don't know exactly what the command is or action that I want to perform,
1:52 if I start typing out what I'm looking for, it'll filter those results and give me a better idea of what might be possible.
1:59 So, in this case, I want to edit settings for the command palette. How can I find those?
2:03 Well, I'll bring up the command palette, Control-Shift-P, and I search for settings.
2:07 And then I can see all the different options that have that keyword in it. And in particular, I realize, oh, I want to open the settings UI.
2:15 Now, once in here, this is what we're talking about. We want to update some of the command palette settings.
2:21 So, I'm going to search for command palette. And here we can see, let's close the bottom panel there. We can see the different options.
2:29 So, we can see the different options that are related to the command palette in VS Code settings. So, we showed those two examples.
2:35 And a few more examples of using the command palette that you might want to leverage it for is maybe changing the editor layout for you.
2:42 So, in this case, you see I have a tab open for settings and another tab open in the editor view for the API.py file. What if we wanted to split those?
2:50 Well, Control-Shift-P, and I look for split editor. And hit enter on that. And now we can see it did indeed. Split the editor.
2:59 We have an editor group on the right-hand side with the settings view open. And then I can close. It looks like it duplicated in this case.
3:07 And then I have the API.py on another side.
3:10 Another option would be, which I personally prefer, is toggling which side of Visual Studio Code the activity bar shows up on.
3:20 So, I'm going to search for activity bar. And you can see, we can focus on it or toggle the visibility of it. We can hide it completely.
3:28 If I hit enter again, you'll notice when you bring up the command palette, it shows your recent command that you executed in that history.
3:36 So, you can quickly jump between them if you need to go back and do something or revert something that you did.
3:41 Toggle the sidebar, primary sidebar position. So, right now, that's on the left-hand side.
3:48 And as I was mentioning before, my personal preference is to have it on the right-hand side. Now that you can see it's over there.
3:54 The reason, really quick, sidebar on this. No pun intended.
3:58 Why I want that on the right-hand side versus the left-hand side is I personally often move around my UI components or hide and show UI components.
4:09 So, in this case, I like to hide and show this sidebar view so that I get more real estate to see my code.
4:17 So, you can click on the currently active view to hide and show that. Or you can press control B or command B if you're on macOS.
4:25 And that will toggle it on and off. In which case, you can hide and show it. In which case, you notice the behavior now.
4:29 It's not as jarring on my eyes when I'm hiding and showing that versus when the sidebar is on the left-hand side.
4:36 So, I'm going to press control B a few times and you'll see the code jumps. The positioning of where the code starts for me to read jumps quite a bit.
4:45 And since I do that a lot in my personal workflow, I prefer it on the right-hand side. And maybe you will, too.
4:52 One last really cool example of the power of the command palette that you can use it for. Is checking out extensions, too.
5:00 So, control shift P to bring it back up. I'm going to search for extensions. And I have some options here. We can check for extension updates.
5:08 Disable some of them. But I want to install, let's say, an extension like this. And it brings me right to the extensions view.
5:15 Another thing you can search for is a lot of times people want to change the color theme of Visual Studio Code.
5:22 You can start customizing it to your liking and be more visually pleasing for you. Well, I can search for theme. Click on this preferences color theme.
5:30 And all within the command palette is when I'm doing this.
5:33 And I can toggle through all the different options that are installed in my instance of Visual Studio Code. Some of these are built in.
5:40 Some are ones that you can install separately. Which also can happen directly from the command palette. You see this top option.
5:48 Sorry for the flashing there. Browse additional color themes. I hit enter on that. And now it's searching the Visual Studio Code marketplace.
5:57 For all the color themes that are available out there. So maybe I want to search for Night Owl is one that I really like by Sarah Drasner.
6:06 And here is the chance where I can actually see a live preview of that searching from the marketplace.
6:13 All within the context of Visual Studio Code and the command palette.


Talk Python's Mastodon Michael Kennedy's Mastodon