如何从“保存格式"中排除文件扩展名和语言在 VSCode 中? [英] How to exclude file extensions and languages from "format on save" in VSCode?

查看:24
本文介绍了如何从“保存格式"中排除文件扩展名和语言在 VSCode 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在 VSCode 设置中,您可以配置保存格式如下:

Currently in VSCode settings you can configure format on save as following:

"editor.formatOnSave": true

我想排除一些文件扩展名,例如只格式化 JavaScript 而不是 HTML 文件.

I want to exclude some file extensions, for example only format JavaScript but not HTML files.

推荐答案

您可以使用 语言特定设置仅针对特定语言启用,例如JavaScript:

You can use language specific settings to enable it for a specific language only, e.g. JavaScript:

"[javascript]": {
    "editor.formatOnSave": true
}

要为特定语言禁用它,您可以将全局默认值切换为 true 并将其与特定于语言的 false 组合:

To disable it for a specific language, you could switch the global default to true and combine it with a language-specific false:

"editor.formatOnSave": true
"[javascript]": {
    "editor.formatOnSave": false
}

请注意,语言特定设置基于语言标识符,而不是直接基于文件扩展名.还有一个开放的功能请求,允许文件扩展名特定设置.

Note that language specific settings are based on language identifiers rather than directly on file extensions. There's an open feature request to allow for file extension specific settings as well.

如果语言 ID 不够具体,可以使用 "files.associations" 将具有特定扩展名和/或特定目录中的文件重新映射到另一个 ID,但是这也会影响语法高亮、代码完成等.例如,这可以禁用 out 目录中 JavaScript 文件的格式,但它们将被视为纯文本:

In cases where the language ID isn't specific enough, "files.associations" could be used to remap files with a specific extension and/or in a specific directory to another ID, but this will affect syntax highlighting, code completion, etc. as well. For instance, this would work to disable formatting for JavaScript files in out directories, but they will be treated as plaintext:

"[javascript]": {
    "editor.formatOnSave": true
},
"files.associations": {
    "**/out/**/*.js": "plaintext"
}

这篇关于如何从“保存格式"中排除文件扩展名和语言在 VSCode 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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