How do i format or beautify code in Visual Studio code?

I have just started using Visual Studio code, but i am not able to format code in it, I have tried ctrl k+ Ctrl d but it doesn't work, any helpful link for it?

Asked by:- jaya
: 23155 At:- 9/22/2017 4:36:23 PM
visual-studio-code code-formatting code-beautify php c#

3 Answers
profileImage Answered by:- Sam

Formatting Code in Visual Studio can be done using the Keyboard shortcuts as below

  • On Windows Shift + Alt + F
  • On Mac Shift + Option + F
  • On Ubuntu Ctrl + Shift + I

you can also find these as well as other shortcuts, through the search functionality provided in the editor with Ctrl +Shift+ P (or Command + Shift + P on Mac), and then search for format document.


For Php developer, if you are working on php you should download php extension format code.

Press F1 and type : ext install PHP Code Format .

Then Shift + Alt + F will work

You can add a keybinding in Preferences --> Keyboard shortcuts.

{ "key": "cmd+k cmd+d", "command": "editor.action.formatDocument" }

Or Visual Studio like:

{ "key": "ctrl+k ctrl+d", "command": "editor.action.formatDocument" }
At:- 9/23/2017 8:18:46 AM
thanks 0
By : jaya - at :- 10/4/2017 11:20:57 AM

profileImage Answered by:- neena

You can also right-click inside the document and then select "Format Document" from the available options, as shown below



You can also enable "Format on save" supported in Visual Studio Code 1.6 or later.

Enable "Format On Save" by setting ( File -> Preferences -> Settings)

"editor.formatOnSave": true
At:- 9/25/2017 12:30:30 PM

profileImage Answered by:- vikas_jk

If none of the above works, you can also, simply install VS Code, code format plugins like

Also, For Fedora or Linux

  • You can click File -> Preferences -> Keyboard shortcuts.
  • Under Default Keyboard Shortcuts, search (Ctrl + F) for editor.action.format.

You will find the shortcut key there, as shown below  (Windows Example, but same in Fedora)


At:- 1/5/2021 12:59:48 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use