Modern Python Projects Transcripts
Chapter: Your code editor
Lecture: Quick overview of VS Code
0:00 Before we start talking about how to use VSCode with Python specifically, let's talk about how to use VSCode in general.
0:09 So, you can see on the left side we have the sidebar. First icon is the file Explorer. I have opened the Django project,
0:16 so, we have some files here. So, we can click a file to open it. And for example, if you have a lot of files and you want to filter.
0:25 You can just start typing in the sidebar. And that way you can filter which file or folder you want to select, under the
0:36 files. We have the outline tab, if you can see a list of all your classes, function and variables in the currently open file.
0:46 So, all those elements with this yellow icon, are classes, inside you would normally see functions,
0:52 but unfortunately, I open the file that doesn't have functions. So, let's try a different one. So here, let's open the outline.
1:06 And here you can see that we have some classes. Then we have some functions. And finally, those are, all variables. One nice thing that you can do.
1:14 If the outline is that you can select follow cursor by default. It's disabled, but if you enable it and you move around the file,
1:22 you can see that the location in the outline is changing. So if you move around the file,
1:27 you will see that the outline on the left side always follow your cursor. Also, you can select how you want to sort all those elements, by default,
1:35 It's by category. So first you have classes, then you have functions and then variables. But also you can sort by position.
1:42 So it started from the top to the bottom or you can sort it by name. I usually like to sort by position and under the outline we have the timeline.
1:53 So, this is a simple Git integration, that will show you all the changes related to this file. So, you can see,
1:59 Three months ago, someone did this small change in this file and also one down here. One year ago, there was a different change and so on and so
2:09 on. So, this is a good tool to see the latest changes to this current file. Next in the sidebar, we have the search, you can search for something,
2:17 and you will immediately see the results this called fuzzy searching. But you can also press control + enter or on MAC command + enter and this
2:27 will open the search results in the new tab. Here you can further narrow down your search,
2:37 but also you can select how many lines around the search results you want to see by default, For each result,
2:46 you will see one line above and one line below. But sometimes maybe you want to see a bit more context. So, we can change this
2:52 number. And then for each result, you will see two lines before and two lines above. Next. We have source control tab. Right now we don't see anything.
3:02 But if we make a change to one of those files and we save it, we can now see this change in the source control tab.
3:08 We can open this file, we can discard changes, or we can make a commit from it. Let's discard it. Next, we have a Debugger.
3:18 Right now, we don't have any configuration,
3:20 so let's skip it. But I will show you later how to use a 03:21.89 debugger. And finally we have the extension tab that we are already familiar with.
3:27 Right now, we see five icons here, but actually more icons might be available when you enable more features.
3:33 For example, when you configure testing framework, you will see an additional tab for tests. When you install a Docker extension,
3:39 you will see an additional side menu for Docker, So that was the side panel.
3:44 But actually, we have yet another panel that we can trigger by running view. Toggle panel. That's right, this one lets actually close those files.
3:55 So at the bottom of your code editor, you will see some additional tabs. First up, it's problems. If you have a linter enabled and there are some
4:03 problems with your code, you can see a list of those problems here. Next we have output. This is where you can see output of various parts of
4:11 VSCode. You are probably not going to use it very often, mostly for some debugging purposes. Speaking of the debugging,
4:22 we have the debug console. So, when you started debugging session, you can go to this debug console and you can execute some statements here.
4:32 And finally we have the terminal tab, which is basically your standard terminal. It's nice to have it here,
4:39 because that way you don't have to switch between VSCode and terminal. You have everything in one window,
4:45 so it's good to remember the shortcut to show and hide terminal. Let's open some files and let's hide this thing. Let's open this one. This one,
4:57 this one. If you have multiple files open, sometimes you want to see, let's say two files side by side.
5:04 So you can easily do this by dragging your file around. That way you can move this file to the right side and then you can move
5:12 this file to the bottom. You can also copy file to the side. So here we have the same file in two places and actually,
5:24 if we modify it here, we can see the modification on the right side. Another useful feature not limited to VSCode is the multi cursor.
5:34 So you can put your cursor in multiple places by pressing option or alt. And that way you only need to type ones to put the same text in multiple
5:44 areas, manually putting this multiple courses in multiple places. It's not very useful, but for example, if you want to, let's say,
5:57 rename a variable; you can select all the currencies off this variable and simply rename
6:01 it, another cool feature related to files is when you want to create a new file, but you also want to create folders on the way there.
6:12 So one way would be to click this add folder and then name this folder. Then inside, you would have to click again add folder to and then you would
6:24 finally, add a file. A much better idea is to simply at forward slashes(/) in the name of the file, and this will create folders for you.
6:39 You can see we have foldera folderb inside we have our file, by the way, when you have a folder that only contains another folder inside.
6:49 VSCode will use this one-line notation to indicate that. So this basically means that inside the foldera, we have only foldera and then inside folderb.
7:00 We have our my_new_file.py, last thing that I want to talk about our keyboard shortcuts. There are few keyboard shortcuts that you will be using
7:09 very often, so it's good to remember them. The most important one opens the command palette on Mac.
7:16 It's command shift P and in other operating systems, I think it's control shift P from the command palette.
7:22 You can run basically any function in VSCode. So instead of clicking things around,
7:26 it's much faster to open command palette and run commands from there. For example, if you don't know what's the keyboard shortcut to start
7:32 debugging can open the common palette and type start debugging, and there we have. Next, we have go to file, which is command+P.
7:42 That way you can quickly open any file from the currently open folder or a project And since this is a fuzzy search,
7:49 you don't even have to type the whole file name. Next, we have go to symbol in file.
7:56 You can quickly jump to a Function, Variable, Class or even the module in the current
8:01 file. And if you want to group classes together and variables together, you can add the colon (:) at the beginning, so you can see here,
8:10 we have one class, five methods and 13 variables in this file. You can also quickly go to a line in the file,
8:18 and you can even combine go to file and go to specific line. So, if we go to a file and then we specified the line number after the
8:27 colon, we will go to Line 15 of the clickjacking.py. The two final useful keyboard shortcuts, that I want to show you.
8:34 It's go to definition and show all references. So, when you have a function, let's say this one, and you want to go to the place where it's defined
8:45 well here. It's kind of easy because it's the same file, but normally it's gonna be in the different file,
8:51 right Click and select Go to definition or is the keyboard shortcut. And when you have a function definition, and you want to find all the places where
8:58 it's being used, you can select go to references. This will show a little pop up with all the references to this function.
9:08 Those are just the most popular keyboard shortcuts that you will be using. But VSCode is full of keyboard shortcuts that you can use, so as you
9:17 go, you will probably learn more and more off them. Basically, almost anything can be done with the keyboard shortcut.
9:24 That's a lot of keyboard shortcuts to remember. So to make it easier, VSCode documentation contains a nice cheat.
9:30 sheet. With the list of most common shortcuts for each operating system, you can find this list in the VSCode documentation.
9:38 But to make it easier, I'm also linking to those cheat sheets from the modernPythonprojects.com website. So, if you want to see the cheat sheet for
9:46 Mac OS, just goto modernPythonprojects.com/vscode-mac If you want to see the one for Linux, replace Mac with Linux and for windows,
9:56 goto /vscode-windows. And finally, if you're moving to VSCode from a different code editor,
10:03 it might be hard for you to get used to having different shortcuts. So, to make it easier, there are some plugins that will actually change the
10:12 default VSCode shortcuts to use shortcuts from your previous code editor, so we can
10:18 go to the extensions marketplace and search for the name of your previous code editor. For example, I moved to VSCode from sublime text.
10:30 So, the first plugin that I ever installed in VSCode was sublime. Text keymap. Once you install it,
10:38 some of the default VSCode shortcuts will be replaced with the shortcuts from sublime text, so it will make the transition to VSCode slightly easier.