Code formatting is essential for developers. A formatted code is easy to understand for other developers and allows us to find issues within the source code quickly. This article will help you to format source code in Visual Studio Code (VSCode) editor on various operating systems.
VSCode – Code Formatting Keyboard Shortcuts
You can format code using the keyboard shortcuts. Use the following key combinations to format code in Visual Studio Code (VSCode).
Shift + Alt + F
: Windows Users
Shift + Option + F: macOS Users
Ctrl + Shift + I: Linux Users
VSCode – Code Formatting Option #2
You can also format code using the options. Right-click on your source’s code content and select the format document. In this way the VSCode will select the default formatted for that language.
If you have multiple code formatter extensions installed for a specific language, you need to click the “Format Document With…” option on the right click. Then select the appropriate formatter.
VSCode – Installing code formatters
When you press the formatting shortcut but no formatter is installed for the specific programming language, You will see a popup like the below:
Click the “Install Formatter…” button, this will search for the available code formatting extension for that programming language. You can install any formatting extension of your choice that supports your language.
The post How to format source code in Visual Studio Code (VSCode) appeared first on TecAdmin.