本文翻译自:How do you format code in Visual Studio Code (VSCode)
在Visual Studio中,Windows上的Ctrl + K + F和Ctrl + K + D等效于Visual Studio代码编辑器中的格式化或“美化”代码?
#1楼
参考:https://stackoom.com/question/21lRF/如何在Visual-Studio代码-VSCode-中格式化代码
#2楼
The code formatting is available in Visual Studio Code through the following shortcuts: Visual Studio Code中的代码格式通过以下快捷方式提供:
- On Windows Shift + Alt + F 在Windows Shift + Alt + F上
- On Mac Shift + Option + F 在Mac Shift + Option + F上
- On Ubuntu Ctrl + Shift + I 在Ubuntu上按Ctrl + Shift + I.
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 . 或者,您可以通过编辑器中使用Ctrl + Shift + P (或Mac上的Command + Shift + P )提供的搜索功能找到快捷方式以及其他快捷方式,然后搜索格式文档 。
#3楼
You can add a keybinding in menu File → Preferences → Keyboard shortcuts. 您可以在菜单文件 → 首选项 → 键盘快捷键中添加键绑定。
{ "key": "cmd+k cmd+d", "command": "editor.action.formatDocument" }
Or Visual Studio like: 或Visual Studio如:
{ "key": "ctrl+k ctrl+d", "command": "editor.action.formatDocument" }
#4楼
在Visual Studio代码中, Shift + Alt + F正在执行Ctrl + K + D在Visual Studio中执行的操作。
#5楼
右键组合为Shift + Alt + F.
#6楼
On Linux it is Ctrl + Shift + I . 在Linux上它是Ctrl + Shift + I.
On Windows it is Alt + Shift + F . 在Windows上,它是Alt + Shift + F. Tested with HTML/CSS/JavaScript and Visual Studio Code 1.18.0. 使用HTML / CSS / JavaScript和Visual Studio Code 1.18.0进行测试。
For other languages, you might need to install a specific language package. 对于其他语言,您可能需要安装特定的语言包。