在Visual Studio中,Windows上的Ctrl + K + F和Ctrl + K + D用于格式化,或在Visual Studio代码编辑器中“美化”代码的等效功能是什么?


当前回答

在Mac上,Shift + Alt + F适合我。

你可以在菜单中检查键绑定:

菜单文件→首选项→键盘快捷键和过滤关键字“格式”。

其他回答

使用扩展……

启用在保存文件时自动格式化代码。

启动Visual Studio Code和快速打开(Ctrl + P),粘贴以下命令,并按Enter。

Ext安装格式保存

https://marketplace.visualstudio.com/items?itemName=gyuha.format-on-save

在Visual Studio Code中,Shift+Alt+F的作用就像在Visual Studio中Ctrl+K+D的作用一样。

右键组合为Shift + Alt + F。

对于那些想要自定义要格式化JavaScript文件的人,可以使用JSfiles属性上的any扩展名。这同样适用于HTML。

{
    "beautify.onSave": true,
    "beautify.JSfiles": ["js", "json", "jsbeautifyrc", "jshintrc", "ts"],
    "beautify.HTMLfiles": ["htm", "html"]
}

这将在保存为TypeScript时启用美化,并且您可以在HTML选项中添加XML。

您可以在菜单文件→首选项→键盘快捷键中添加按键绑定。

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

或者像Visual Studio那样:

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