How to format code in Visual Studio Code

0

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.

PHP Screengrab

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

The formatted code makes life easy for the 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 the Format Document option

The shortcut key to format a 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

The shortcut key to format the document is Ctrl+K Ctrl+F

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

You are Done!!!

Leave a Reply

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