How To Format Source Code In Visual Studio Code (VSCode)

Skip to content Mkyong.com Mkyong.com Menu

This article shows how to format source code in Visual Studio Code (VSCode).

Tables of contents

  • 1. VSCode – Code Formatting Shortcuts
  • 2. VSCode – Code Formatting Shortcut #2
  • 3. Formatter is not installed
  • 4. References

1. VSCode – Code Formatting Shortcuts

The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations:

  • On Windows Shift + Alt + F
  • On macOS Shift + Option + F
  • On Linux Ctrl + Shift + I

Note It works for all source codes like HTML, Java, Python, JavaScript ad, etc., it is working the same way.

2. VSCode – Code Formatting Shortcut #2

Alternatively, click on the source code editor, right clicks and select the Format Document option.

format document vscode

3. Formatter is not installed

If we press the code formatting shortcuts and VSCode can’t find any formatter for the specified source code, and VSCode will pop out a dialog at the right-bottom and ask you to install the suggested formatter for the source code;

3.1 Below example shows the VSCode request to install the Python formatter autopep8.

vscode python formatter

3.2 Clicks Yes button, and VSCode will install the autopep8 formatter automatically.

vscode python formatter

3.3 Try to format the source code again; now, the VSCode will auto-format the Python source code using the installed Python formatter.

4. References

  • Basic Editing in Visual Studio Code
  • Pyhton formatter autopep8

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

Label Name* Email* Label Name* Email* 0 Comments Most Voted Newest Oldest Inline Feedbacks View all comments

Related Posts

  • Java – How to round double / float value to 2 decimal places
  • Eclipse – How to know this class belongs to which JAR

Mkyong.com has provided Java and Spring tutorials, guides, and code snippets since 2008. All published articles are simple, easy to understand, and well-tested in our development environment.

Mkyong.com licenses all source code on this website under the MIT License.

Tools
  • Spring Framework
  • Quarkus Framework
  • Micronaut Framework
  • Oracle Java JDK
  • Eclipse Temurin JDK
  • OpenJDK JDK
  • Hibernate ORM
  • Maven Build Tool
  • Gradle Build Tool
  • Tomcat Application Server
  • Docker
Links
  • Maven Central
  • Docker Hub
  • Spring Guides
  • Quarkus Guides
  • Micronaut Guides
  • Martin Fowler
  • AskPython
About
  • About Us
  • Code License
  • Privacy Policy
  • Terms Of Use
  • Contact Us
Insert Search for:

Từ khóa » Visual Studio Code Run Python Keyboard Shortcut