Bra*_*app 990 code-formatting visual-studio-code
在Visual Studio中,Windows上的Ctrl+ K+ F和Ctrl+ K+ 相当于D在Visual Studio代码编辑器中格式化或"美化"代码?
Bra*_*app 3417
Visual Studio Code中的代码格式通过以下快捷方式提供:
或者,您可以通过编辑器中使用Ctrl+ Shift+ P(或Mac上的Command+ Shift+ P)提供的搜索功能找到快捷方式以及其他快捷方式,然后搜索格式文档.
Bha*_*asu 451
代码格式快捷方式:
Windows上的VSCode - Shift+ Alt+F
MacOS上的VSCode - Shift+ Option+F
Ubuntu上的VSCode - Ctrl+ Shift+I
如果需要,您还可以使用首选项设置自定义此快捷方式
保存文件时的代码格式:
Visual Studio代码允许用户自定义默认设置.
如果您想在保存的同时自动格式化您的内容,请在Visual Studio代码的工作空间设置中将此下面的代码段添加.
文件 - >首选项 - >工作区设置
{
// 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"
]
}
Run Code Online (Sandbox Code Playgroud)
注意:现在您可以自动格式化typescript文件检查我的更新
har*_*ded 207
您可以在菜单文件 → 首选项 → 键盘快捷键中添加键绑定.
{ "key": "cmd+k cmd+d", "command": "editor.action.formatDocument" }
Run Code Online (Sandbox Code Playgroud)
或Visual Studio如:
{ "key": "ctrl+k ctrl+d", "command": "editor.action.formatDocument" }
Run Code Online (Sandbox Code Playgroud)
Sid*_*ted 157
小智 116
正确的组合键是Shift+ Alt+ F.
aby*_*kla 62
对于Fedora
File
- > Preferences
- > Keyboard shortcuts
.Default Keyboard Shortcuts
,搜索(Ctrl+ F)editor.action.format
.我看了 "key": "ctrl+shift+i"
你也可以改变它.请参阅这个答案,了解如何......或者如果您感觉有点懒,可以向上滚动:
您可以在"首选项 - >键盘快捷键"中添加键绑定
{ "key": "cmd+k cmd+d", "command": "editor.action.format" }
或Visual Studio如:
{ "key": "ctrl+k ctrl+d", "command": "editor.action.format" }
请注意: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
Nik*_*ntz 61
在Linux上它是Ctrl+ Shift+ I.
在Windows上它是Alt+ Shift+ F.使用HTML/CSS/JavaScript和Visual Studio Code 1.18.0进行测试.
对于其他语言,您可能需要安装特定的语言包.
Dar*_*usz 58
VS Code 1.6.1 支持" 保存格式 ",它将自动获取相关的已安装格式化程序扩展,并在每次保存时格式化整个文档.
通过设置启用"保存格式"
"editor.formatOnSave": true
Run Code Online (Sandbox Code Playgroud)
并且有可用的键盘快捷键(VS Code 1.7及以上版本):
格式化整个文档:Shift+ Alt+F
仅限格式选择:CtrlK+CtrlF
小智 25
由于某些原因,Alt+ Shift+ F在Mac VSC 1.3.1上对我不起作用,实际上命令"格式文档"根本不起作用.但命令Formatter工作得很好.
因此,您可以使用Command+ Shift+ P并键入Formatter或在Preferences/Keyboard Shortcuts Command+ K Command+中创建自己的快捷方式,S然后键入Formatter并添加快捷方式,请参阅示例:
小智 21
文件 - >首选项 - >设置
"editor.formatOnType": true
Run Code Online (Sandbox Code Playgroud)
当你输入分号时,它将被格式化
afe*_*eef 20
在Visual Studio中格式化代码.
我尝试在Windows 8中进行格式化.
只需按照截图即可.
步骤1.单击顶部菜单栏上的视图,然后单击Command Pallete.
移位+ Alt + F
Sat*_*ies 14
虽然更改Visual Studio代码的默认行为需要扩展,但您可以覆盖工作区或用户级别的默认行为,并适用于大多数支持的语言(我可以保证html,javascript,c#)
优点
成果
.vscode/settings.json
在项目根文件夹中创建如何?
转到:文件 - >首选项 - >工作区设置
添加并保存"editor.formatOnType": true
到settings.json(通过创建.vscode/settings.json文件覆盖您所处理项目的默认行为).
优点
成果
settings.json
已修改(请参阅下面的操作系统位置)如何?
转到:文件 - >首选项 - >用户设置
在用户settings.json中添加或更改"editor.formatOnType": false
to 的值"editor.formatOnType": true
您的Visual Studio Code用户的settings.json
位置是:
设置文件位置根据您的平台,用户设置文件位于:
Windows%APPDATA%\ Code\User\settings.json Mac $ HOME/Library/Application Support/Code/User/settings.json Linux $ HOME/.config/Code/User/settings.json工作区设置文件位于项目中的.vscode文件夹.
更多细节可以在这里找到
默认这个键对我来说不适用于HTML,CSS,JS文档.
搜索后我发现这个流行的插件JS-CSS-HTML Formatter在安装 后安装了133,796只需重新加载windows并点击CTRL+ SHIFT+ F就可以了!
对于那些想要自定义要格式化的JavaScript文件的用户,可以使用属性上的任何扩展名JSfiles
。同样适用于HTML。
{
"beautify.onSave": true,
"beautify.JSfiles": ["js", "json", "jsbeautifyrc", "jshintrc", "ts"],
"beautify.HTMLfiles": ["htm", "html"]
}
Run Code Online (Sandbox Code Playgroud)
这将在保存时美化TypeScript,并且您可以将XML添加到HTML选项。
归档时间: |
|
查看次数: |
1990863 次 |
最近记录: |