How to format code in Visual Studio Code

You code fast and could not maintain the formatting of the code and or you…

You code fast and could not maintain the formatting of the code and or you keep getting Pull Request review comments about your poor code format.

The formatted code makes life easy for reader and reviewer.

Follow the simple tips given on this blog and it will make your life easy with a few clicks.

If you want to auto-format your code in Visual Studio Code you have to enable the setting.

1.  Go to File > Preferences > Settings

2. In Search, bar enter formatOnSave

3. Checkmark the setting and it will automatically save the setting

4. Close and reopen Visual Studio Code

FORMAT DOCUMENT OF CODE IN VISUAL STUDIO CODE

1. Double click and open TypeScript or JavaScript document

2. Right click on the document

3. Select Format Document option

Shortcut key to format document is Shift+Alt+F

FORMAT SELECTION OF CODE IN VISUAL STUDIO CODE

1. Double click and open TypeScript or JavaScript document

2. Select the code you want to format

3. Select the Format Selection option

Shortcut key to format document is Ctrl+K Ctrl+F

When you write any code and Save changes then your code will be auto-formatted.

You are Done!!!

1 thought on “How to format code in Visual Studio Code

Leave a Reply

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