How To Format Code in Visual Studio Code (Automatic and Manual Method)

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.

code format

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:

The keyboard shortcut for code formatting in VS Code
Operating systemsKeyboard Shortcut
WindowsShift + Alt + F
MacShift + Option + F
LinuxCtrl + 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.

keyboard shortcut for code formatting

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.

VS Code extension

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.

Post a Comment (0)
Previous Post Next Post