How to Automatically Indent Code in Visual Studio Code

Indenting code makes the code more structured and easy to read. It allows us to tidy up our code which enhances the workflow. There are two methods to indent code in Visual Studio Code. This guide shows how to indent code in Visual Studio Code using both methods.

Auto-Indentation through Settings

By default, auto-indentation is disabled on Visual Studio Code. To enable the auto-indentation, follow the below steps:

  1. From the top-level “File” menu, select the Preferences option. From the sub-menu, choose the Settings option. Alternatively, you can press Ctrl + ,

    Open the Settings window by pressing Ctrl + , on your keyboard.
  2. In the search bar, type “indent”.

    Search Indent
    Enter “indent” In the search bar.
  3. Choose the option full from the “Editor: Auto Indent” drop-down.

    Choose the full option from the “Editor: Auto Indent” drop-down.
  4. Auto-indentation is now enabled.

Auto Indent code on Save

Visual Studio Code has built-in support for automatic formatting (including indentation) upon saving the document. We have written a guide on enabling this here.

Was this article helpful?

Leave a Comment