How do you format code in Visual Studio Code (VSCode)
Windows上的Ctrl + K + F和Ctrl + K + D相当于在Visual Studio代码编辑器中进行格式化或“美化”代码的等效代码?
The code formatting is available in VS Code through the following shortcuts:
Alternatively, you can find the shortcut, 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 searching for format document .
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" }
Code Formatting Shortcut:
VSCode on Windows - Shift + Alt + F
VSCode on MacOS - Shift + Alt + F
VSCode on Ubuntu - Ctrl + Shift + I
You can also customize this shortcut using preference setting if needed.
Code Formatting While Saving the File:
Visual Studio code allows user can customize the default settings.
If you want to auto format your content while saving add this below code snippet in work space settings of visual studio code.
File --> Preferences --> Workspace Settings
{
// Controls if the editor should automatically format the line after typing
"beautify.onSave": true,
"editor.formatOnSave": true,
// You can auto formate any files based on extensions type.
"beautify.JSfiles": [
"js",
"json",
"jsbeautifyrc",
"jshintrc",
"ts"
]
}
Note: now you can auto format typescript files check my update
链接地址: http://www.djcxy.com/p/25450.html