VSCode:如何在保存时自动格式化? [英] VSCode: How do you autoformat on save?

查看:486
本文介绍了VSCode:如何在保存时自动格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio Code中,保存文件后如何自动格式化源代码?

In Visual Studio Code, how do you automatically format your source code when the file is saved?

推荐答案

启用保存时格式化"通过设置

Enable "Format On Save" by setting

"editor.formatOnSave": true

并且由于版本 1.49.0 editor.formatOnSaveMode具有选项modifications,该选项将仅格式化您修改的代码 .当您更改其他人的代码时很棒.

And since version 1.49.0 editor.formatOnSaveMode has the option modifications that will just format the code you modified. Great when you change someone else code.

您还可以仅针对一种特定语言进行设置:

You can also set it just for one specific language:

"[python]": {
    "editor.tabSize": 4,
    "editor.insertSpaces": true,
    "editor.formatOnSave": true #
},

自版本 1.6.1 起,Vscode支持"保存时格式化".它将自动使用相关的已安装格式化程序扩展名来格式化整个文档.

Since version 1.6.1, Vscode supports "Format On Save". It will automatically use a relevant installed formatter extension to format the whole document.

这篇关于VSCode:如何在保存时自动格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆