如何在VS Code中保存时格式化代码 [英] How do you format code on save in VS Code
本文介绍了如何在VS Code中保存时格式化代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在Visual Studio Code中保存文件时,我想使用内置格式化程序自动格式化TypeScript代码。
I would like to automatically format TypeScript code using the build-in formatter when I save a file in Visual Studio Code.
我知道以下选项,但是它们都不足够好:
I'm aware of the following options, but none of them is good enough:
- 手动设置格式
Shift + Alt + F
- 在类型
editor.formatOnType上设置格式: true
- 在按Enter时会格式化行。不幸的是,当您单击另一行或按向上/向下箭头时,它保持未格式化的状态。
- 我尝试了此一个,但效果似乎不太好。
- I tried this one, but it does not seem to work too well.
- 不适用于TypeScript
- 如果要处理自动保存并正确构建,这将非常棘手。
推荐答案
截至2016年9月( VSCode 1.6),现已正式受支持。
As of September 2016 (VSCode 1.6), this is now officially supported.
将以下内容添加到您的
settings.json
文件中:Add the following to your
settings.json
file:"editor.formatOnSave": true
这篇关于如何在VS Code中保存时格式化代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文