12 VSCode Tips and Tricks for Python Development

Simple tips on doing less and achieving more from VSCode.



12 VSCode Tips and Tricks for Python Development
Image by Author

 

Virtual Studio Code (VSCode) is one of the popular Integrated Development Environments (IDE) for Python development. It is fast and comes with rich features that make the development experience fun and easy.  

VSCode Python extensions are one of the prominent reasons that I use it for all work-related tasks. It provides you syntax autocomplete, linting, unit testing, Git, debugging, notebooks, editing tools, and the ability to automate most of your tasks. Instead of doing things manually, you get to either press keyboard shortcuts or click a few buttons.   

In this post, we will be learning how we can take the VSCode to the next level and get more productive at building Python software and solutions. 
 

Note: If you are new to VSCode and want to learn all of the basics, read the Setting Up VSCode For Python tutorial to understand key features. 

 

1. Command line

 

You can launch VSCode from Terminal or Bash using CLI commands. 

  1. Open VSCode in the current directory: code .
  2. Open VSCode in the current directory in the most recently used window:  code -r .
  3. Create a new window: code -n
  4. Open file diff editor VSCode: code --diff <file1> <file2>

 

2. Command Palette

 

Access all available commands and shortcuts based on the current context. You can initiate Command Palette by using the keyboard shortcut: Ctrl+Shift+P. After that, you can type related keywords to access specific commands. 
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

3. Keyboard shortcuts

 

What is better than a Command Palette? Keyboard shortcuts. You can modify keyboard shortcuts to your needs or learn about default keyboard shortcuts by reading the keyboard-shortcuts reference sheet. 

Keyboard shortcuts will help us access the commands directly instead of scrolling through the command palette options.

 

4. Errors and warnings

 

Quickly access the errors and warnings by using the keyboard shortcut: Ctrl+Shift+M and cycle through them by clicking on the warning or pressing  F8 or Shift+F8 keys. 
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

5. Fully Customizable Development Environment

 

You can customize themes, Icons, keyboard shortcuts, debugging settings, fonts, linting, and code snippets. VSCode is a fully customizable developer environment that lets you even create your own extension.  

 

6. Extensions

 

Python’s VSCode extensions can improve the development experience and make you productive. It is not all about productivity. It is also about visuals. Most popular Python extensions on the Visual Studio Marketplace provide interactive GUI with stats and graphs.
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

Check out my list of 12 Essential VSCode Extensions for Data Science that will make VSCode a super app so that you can perform all of the data science tasks without leaving the application. 

 

7. Jupyter Notebook

 

The most important extension that lets you perform data analysis and machine learning experiments is the Jupyter Notebook extension. 
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

This extension is highly recommended for data scientists for performing data science experimentation and building production-ready code. 

 

8. Multi-cursor selection

 

Multi-cursor selection is a lifesaver when you have to do multiple edits of the same instance. 

  • Add multiple cursor points by using Alt+Click
  • To set the cursor above use Ctrl+Alt+Up or below Ctrl+Alt+Down
  • Add additional cursors to all occurrences of the current selection using Ctrl+Shift+L

 

12 VSCode Tips and Tricks for Python Development
Image from Visual Studio Code

 

9. Search and modify

 

I know this is a simple feature but it is quite handy when you are editing similar variables, arguments, and parameters at various places in the file. You can search and replace them one by one or all at one. 

To rename the symbol or argument, select the symbol and press the F2 key.  
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

10. Built-in Git Integration

 

It is a built-in integration that allows you to perform all Git-related tasks by clicking on a few buttons instead of typing the Git command in CLI. You can visualize history, see the difference, and create new branches all by interacting with a user-friendly GUI. It is even easier than the GitHub Desktop app. 
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

11. Code Snippets

 

Code snippets are just like autocomplete, but you have more power over them. You can create custom code snippets for repeating code patterns. Instead of creating a Python function, you can type a word, and it will fill the rest. 

To create a custom code snippet, select File > Preferences > Configure User Snippets and then select the language.
 

12 VSCode Tips and Tricks for Python Development
Image by Author

 

12. GitHub Copilot

 

Everyone is talking about ChatGPT for code suggestions, but GitHub Copilot has been there for more than two years, and it is getting better at understanding user behavior and assisting them in writing fast and effective code. GitHub Copilot is based on GPT-3, which enhances the development experience by suggesting lines of code or entire functions.
 

12 VSCode Tips and Tricks for Python Development
Image from GitHub Copilot

 
 
Abid Ali Awan (@1abidaliawan) is a certified data scientist professional who loves building machine learning models. Currently, he is focusing on content creation and writing technical blogs on machine learning and data science technologies. Abid holds a Master's degree in Technology Management and a bachelor's degree in Telecommunication Engineering. His vision is to build an AI product using a graph neural network for students struggling with mental illness.