Coding is not so much easy. It gets more difficult when the code looks like a bunch of unexplained alien characters. To make the code human-readable we need to format that. In this article, I am going to show you that how you can format code in your VS Code.
How to format code in Visual Studio Code
VS code is the most popular code editor. There is basically two way you can apply to formate your code in this code editor. You can use the keyboard shortcut or you can use extensions to do that. Here I am going to cover both of them.
Format code using the keyboard shortcut
Write some valid code on the VS Code editor. Then you have to use a keyboard shortcut. Here is the Keyboard shortcut:
Operating systems | Keyboard Shortcut |
Windows | Shift + Alt + F |
Mac | Shift + Option + F |
Linux | Ctrl + Shift + I |
For example, if you are a windows user then press the shift, alt, and F keys at the same time. Use 3 fingers to do that.
Format code using the extensions
You can find many extensions for code formatting. To install extensions you have to go extensions section of your VS Code. Then search code formatter. There are many popular extensions you can find on vs code. You can also use formatter for specific languages like CSS formatter.
Prettier - Code formatter is a popular extension for making code good-looking. Here is a video that will guide you to install 'Prettier - Code formatter'.
Conclusion
Nicely formatted code can be very helpful for others to understand the code. It makes code much easier to debug. It is important to make development career hassle-free. Install external extensions only if your computer can handle the load. If the device you use is not strong then avoid installing extensions.