How to format code in Visual Studio Code (VSCode) 2022
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
Shift
+Alt
+F
- On Mac
Shift
+Option
+F
- On Linux
Ctrl
+Shift
+I
Alternatively, you can find the shortcut and other shortcuts through the ‘Command Palette’ provided in the editor with Ctrl
+Shift
+ P
(or Command
+ Shift
+ 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:
F1
orCtrl
+Shift
+P
) - 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”)
Read More: VISUAL STUDIO CODE “ERROR WHILE FETCHING EXTENSIONS. XHR FAILED – V”
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
- Press
Ctrl
+P
and paste this command:ext install esbenp.prettier-vscode
- After pasting the command, press enter and the extension will install on your VSCode
To the techview71.com admin, Thanks for the detailed post!