Using Python with VS Code – 3 Tips & Tricks Help You to Write Code Faster

VS Code Python Tips Tricks

If you are using Visual studio code to write a Python application, you may think it does not offer many tools.  VS code is not built to create Python applications. But if you want the freedom to customize & a lightweight IDE, you can choose VS code.

Here I am listing some shortcut keys, and setups to write your code faster in Visual Studio code.

Write a multiline comment with a shortcut key

To comment on multiple lines in a Python file,

Select the code lines and press the Shift + Alt + A shortcut key.

That’s it you will get multi-line comments like this

""" excel = client.Dispatch("Excel.Application")

sheets = excel.Workbooks.Open(r'D:\Chromedriver\output.xlsx')

work_sheets = sheets.Worksheets[0] """

Change indentation from 2 spaces to 4 spaces for Python file only

When you write code like function, loop, if-else statement, etc you have to use 4 space indentation.  But by default, Visual studio code applies 2 space indent when you press the Tab key.

To change it to 4 spaces, go to VS code Extensions.

Search and install the EditorConfig for VS Code plugin in VS code editor.

Now in VS Code workspace, select your Python project folder -> right click and choose “Generate .editorconfig”.

It will create .editorconfig file in that folder.

Now add the following line in .editorconfig file.

[*.py]
indent_style = space
indent_size = 4

Save the file.

Now in your python file, select a particular line of code you want to indent and press the Tab key on your keyboard. That’s it. It will apply 4 spaces for the indentation.

for conten in content:
    title = conten.get_text()
    content_title.append(title)

Set keyboard shortcut to run python file in VS code Terminal

In VS Code editor, open the command palette by pressing the “F1” key.

Type and search “Python: Run Python file in Terminal”.

Click the settings icon in the right corner.

For this command, click the Keybinding and add the shortcut key.

Here I am using ctrl + 1 to run the Python file.

That’s it.

Kite Plugin for VS Code 

Visual Studio code offers Code Autocomplete and IntelliSense. But Kite, 3rd party plugin for VS code gives a super-fast auto-complete experience.

First, in VS code Extension, search and install “Kite AutoComplete AI Code”.

Then open your Python file. In VS code terminal, it will show a message like “Kite requires the Kite Copilot desktop application’.

Click install. It will install a standalone kite application on your computer.

Then close open VS code. You will check if the Kite is ready for code auto-completion or not in VS Terminal.

That’s it. I hope this tutorial will help you to write Python code faster in Visual Studio code. If you know any other tips and tricks for Python VS code, do let us via the comment form.