Learn keyboard shortcuts that will make you a more efficient and productive Python programmer with VS Code.
As a Python programmer, I spend my day inside my IDE. After all, it's my job!
This article will share some VS Code keyboard shortcuts that save me hours every week and make me a much more productive Python programmer. I will explain what each shortcut does and I will show a short video example.
(I will show the specific keyboard shortcuts for VS Code, but these actions are common and your IDE is likely to have a similar shortcut!)
All the shortcuts that will be shown are bound to a specific action and the shortcuts can always be edited to better suit your needs. If you forget a specific shortcut, you can open the command palette (which also shows all commands available) and you can type the name of the command you want to see the shortcut for.
To open the command palette, use:
To edit multiple occurrences of the same word (or of the same selection of text), use:
Each time you press the shortcut, you select the next occurrence of the word. When you have selected as many occurrences as you want, start typing to edit them!
You can also use Ctrl + Shift + L to select all occurrences at once. (Use Cmd instead of Ctrl on a Mac.)
If you want to jump to the definition of something (for example, a variable, an attribute, a function, etc), you can use:
When you press this combination, you will see a dropdown with all the symbols in the current file. You can start typing the name of the thing you want to find and select it to jump to its definition.
This is useful when you are in a big file and you want to find a specific function, for example.
Similarly, if you want to jump to the definition of a symbol when you are in a place where it is used, you can hold Ctrl (or Cmd on Mac) and click the symbol. This will jump to the definition site of that symbol. Conversely, if you click a symbol in its definition site, it will open a pane with all the usages of that symbol that VS Code can find.
Note that this pane is not guaranteed to list all usages; for example, this can fail on highly dynamic code that uses
To rename a symbol, like a variable, a class, a function, a method, etc, you can press F2 on top of the symbol. This will rename all occurrences of the symbol that VS Code can find in the current project.
Note that it is not guaranteed that this will rename all occurrences; for example, this can fail on highly dynamic code that uses
You can also preview the change before making it.
To jump to a specific line number, you can use Ctrl + G (for example, after seeing a traceback with a specific line number).
After jumping around a lot, you may need to go back to where you were and you may not remember. To go back to your previous cursor position, use:
These are some shortcuts I use very often. These shortcuts can be edited and configured to better suit your taste.
I hope you learned something new! If you did, consider following the footsteps of the readers who bought me a slice of pizza 🍕. Your contribution boosts my confidence and helps me produce this content for you.