typescript VSCODE 自动格式化代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43247742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:40:45  来源:igfitidea点击:

Auto format of code in VSCODE

typescriptvisual-studio-code

提问by Noam

I'm a long time visual studio developer and am stating with VSCode.

我是 Visual Studio 的长期开发人员,正在使用 VSCode 进行说明。

I found the "Format Code" shortcut (Shift + alt + f) but I want it to run automatically whenever i press ';'. Is there a configuration for that?

我找到了“格式代码”快捷方式(Shift + alt + f),但我希望它在我按下“;”时自动运行。有这样的配置吗?

采纳答案by Sebastian Sebald

You can choose one of the below options

您可以选择以下选项之一

"editor.formatOnType": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": false

Or create a custom keyboard shortcut by editing editor.action.formatDocument. But I AFAIK there is no option to execute the command whenever you press ;. You can set a keyboard shortcut, but I guess you're not able to write ;anymore then :D

或者通过编辑创建自定义键盘快捷键editor.action.formatDocument。但我发誓,无论何时按下 ,都没有执行命令的选项;。你可以设置一个键盘快捷键,但我猜你不能再写;了 :D

回答by Nick N.

To open your user and workspace settings, use the following VS Code menu command:

要打开您的用户和工作区设置,请使用以下 VS Code 菜单命令:

On Windows/Linux - File > Preferences > Settings

On macOS - Code > Preferences > Settings

在 Windows/Linux 上 - 文件 > 首选项 > 设置

在 macOS 上 - 代码 > 首选项 > 设置

Add these options to the editable panel of your configuration settings:

将这些选项添加到配置设置的可编辑面板:

"editor.formatOnPaste": true,
"editor.formatOnSave": true

enter image description here

在此处输入图片说明

回答by FritzHH

Hi so I was trying to find the answer to the semicolon format thing, because it was doing it on my old computer but not my new one. You just have to change editor.formatOnType = true in your json config settings. A few years late but maybe it will help other people!

嗨,所以我试图找到分号格式问题的答案,因为它是在我的旧电脑上而不是我的新电脑上做的。您只需要在 json 配置设置中更改 editor.formatOnType = true 。晚了几年,但也许它会帮助其他人!