Lots of programmers write code on Visual Studio Code and if the code format looks better, it will be helpful to read in the future. Or for normal purpose, all programmer needs to know how to format code.
The code formatting is available in Visual Studio Code through the following shortcuts:
- On Windows
- On Mac
- On Linux
Alternatively, you can find the shortcut and other shortcuts through the ‘Command Palette’ provided in the editor with
P on Mac), and then search for the format document.
For unsaved snippets
Now I’m going to show you that, how you can format unsaved snippets.
- Open the command palette (For windows:
- Find “Change Language Mode” and press enter
- After that, select language e.g. JSON. By now syntax should be highlighted.
- Format document (e.g. Open Command Palette -> “Format Document”)
VSCode extension for code format
You can install the prettier extension to format your code on Visual Studio Code (VSCode). It’s a great extension and I personally use this one.
How to Install Prettier Extension
Follow these steps to install the prettier extension on your VSCode.
- Launch Visual Studio Code or VSCode
Pand paste this command:
ext install esbenp.prettier-vscode
- After pasting the command, press enter and the extension will install on your VSCode