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:
- From the top-level “File” menu, select the Preferences option. From the sub-menu, choose the Settings option. Alternatively, you can press Ctrl + ,
- In the search bar, type “indent”.
- Choose the option full from the “Editor: Auto Indent” drop-down.
- 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.