在Visual Studio中,Windows上的Ctrl + K + F和Ctrl + K + D用于格式化,或在Visual Studio代码编辑器中“美化”代码的等效功能是什么?
当前回答
代码格式化快捷方式:
Visual Studio Code on Windows - Shift + Alt + F
Visual Studio Code on MacOS - Shift + Option + F
Visual Studio Code on Ubuntu - Ctrl + Shift + I
如果需要,还可以使用首选项设置自定义此快捷方式。
保存文件时的代码格式:
Visual Studio Code允许用户自定义默认设置。
如果您想在保存时自动格式化您的内容,请在Visual Studio code的工作空间设置中添加以下代码片段。
菜单文件→首选项→工作空间设置
{
// Controls if the editor should automatically format the line after typing
"beautify.onSave": true,
"editor.formatOnSave": true,
// You can auto format any files based on the file extensions type.
"beautify.JSfiles": [
"js",
"json",
"jsbeautifyrc",
"jshintrc",
"ts"
]
}
注意:现在你可以自动格式化TypeScript文件。看看我的更新。
其他回答
在我安装Mono for Mac OS X、DNVM和DNX之前,c#中的格式快捷方式对我不起作用。
在我安装Mono之前,自动格式化快捷键(Shift + Alt + F)只适用于.json文件。
代码格式化快捷方式:
Visual Studio Code on Windows - Shift + Alt + F
Visual Studio Code on MacOS - Shift + Option + F
Visual Studio Code on Ubuntu - Ctrl + Shift + I
如果需要,还可以使用首选项设置自定义此快捷方式。
保存文件时的代码格式:
Visual Studio Code允许用户自定义默认设置。
如果您想在保存时自动格式化您的内容,请在Visual Studio code的工作空间设置中添加以下代码片段。
菜单文件→首选项→工作空间设置
{
// Controls if the editor should automatically format the line after typing
"beautify.onSave": true,
"editor.formatOnSave": true,
// You can auto format any files based on the file extensions type.
"beautify.JSfiles": [
"js",
"json",
"jsbeautifyrc",
"jshintrc",
"ts"
]
}
注意:现在你可以自动格式化TypeScript文件。看看我的更新。
在Visual Studio中格式化代码。
我尝试在Windows 8中格式化。
照着下面的截图就可以了。
单击顶部菜单栏上的“视图”,然后单击“命令面板”。 然后一个文本框将出现在我们需要键入格式 Shift + Alt + F
对于Fedora
单击文件->首选项->键盘快捷方式。 在默认键盘快捷键下,搜索(Ctrl + F) editor.action.format。
我的是“键”:“ctrl+shift+i”
你也可以改变它。参考这个关于如何……的答案。或者如果你觉得有点懒,就向上滚动:
您可以在“首选项->键盘快捷键”中添加一个键绑定 {“关键”:“cmd + k cmd + d”,“命令”:“editor.action。格式”} 或者像Visual Studio那样: {"key": "ctrl+k ctrl+d", "command": "editor.action. "格式”}
请注意:cmd键仅适用于mac电脑。对于Windows和Fedora (Windows键盘)使用Ctrl
编辑:
根据Visual Code版本1.28.2,这是我发现的。
Editor.action.format不再存在。它现在已经被editor.action.formatDocument和editor.action.formatSelection所取代。
在搜索框中输入editor.action.format查看现有的快捷方式。
按以下步骤更改键组合:
单击editor.action.formatDocument或editor.action.formatSelection 一个笔一样的图标出现左键点击它。 弹出窗口出现。按所需的组合键并按enter。
在Mac上,Shift + Alt + F适合我。
你可以在菜单中检查键绑定:
菜单文件→首选项→键盘快捷键和过滤关键字“格式”。
推荐文章
- 如何在Python中拆分这一长行?
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。VSCode中的json
- 如何格式化Visual Studio Code项目中的所有文件?
- Pylint在Visual Studio代码中“未解决的导入”错误
- 如何在VS Code中默认打开文本换行
- 在Visual Studio代码中更改突出显示文本的颜色
- Visual studio代码-键盘快捷键-全部展开/折叠
- Visual Studio Code无法检测已安装的Git
- 禁用Visual Studio代码中的工具提示提示
- Visual Studio Code -将空格转换为制表符
- 在VSCode中的列自动硬换行
- Visual Studio Code:格式没有使用缩进设置
- 如何排除文件扩展名和语言从“格式保存”在VSCode?
- Visual Studio代码- URI的目标不存在" package:flutter/material.dart "