问题
Hello I am asking how to format code in Visual Studio Code the last update on Windows.
I tried ctrl k+ Ctrl d
doesn't work ..
I also tried Shift + Alt + F
. it didn't work too.
So please help me and it isn't duplicate because i tried the following solution:
How do you format code in Visual Studio Code (VSCode)
回答1:
if you are working on php you should download php exension format code.
Press F1
and type : ext install PHP Code Format
.
Then Shift + Alt + F
will work
回答2:
You can also select the code you want to format and right click, find the format code menu item and it should have the keyboard command listed next to it.
By default it should be Shift + Alt/Option + F.
回答3:
Simply use Ctrl + Shift + I
Or
Right Click on document and Click on Format Document
回答4:
If it's for javascript, JSON, CSS, Sass, and HTML, there no better than beautify extension, simple and very useful! once installed the way you do it are described here with good illustration (to avoid content duplication) https://stackoverflow.com/a/46855721/7668448
For others languages, you add the appropriate extensions and you can set keybinding (you need to get the appropriate command to execute, and add the keybinding to keybindings.json) i have explained that in the link above. Always read well the documentation of the extensions. There you can find all the possible configuration and so.
For specific languages you can search via vscode in extension marketplace, enter just beautify and you will see all the different beautify extension for the different languages. Also you can use formatting format formatter keywords, like php formatting and so
Also you can and may use the integrated formatting tool of vscode. mostly by clicking right and selecting formatting document, you can format also just a selection.
here the shortcut for formatting the whole document that :
- On Windows Alt + Shift + F
- On Mac Shift + Option + F
- On Ubuntu Ctrl + Shift + I
回答5:
As abdullam
mentioned in his comment, the shortcut that worked for me is
Shift + Alt + F.
(The accepted answer didn't work for me. I am using Visual Studio Code on a Mac. I couldn't find the extension mentioned above i.e ext install PHP Code Format.)
来源:https://stackoverflow.com/questions/35984564/how-to-format-code-in-visual-studio-code