Programming

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.

  1. Open the command palette (For windows: F1 or Ctrl+Shift+P)
  2. Find “Change Language Mode” and press enter
  3. After that, select language e.g. JSON. By now syntax should be highlighted.
  4. 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.

code

Prettier Extension Link

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

 

What is your reaction?

0
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly

Comments

  1. To the techview71.com admin, Thanks for the detailed post!

Leave a reply

Your email address will not be published. Required fields are marked *