Visual Studio Code非XML/HTML文件自动补全<>异常求助
解决VS Code非XML/HTML文件中<自动补全>的问题
操作步骤
1. 打开设置JSON文件
按下Ctrl+,(Windows/Linux)或Cmd+,(Mac)打开设置面板,点击右上角的**{}**图标切换到JSON编辑模式。
2. 添加自定义语言配置
将以下配置粘贴到settings.json中,按需调整文件类型:
// 全局设置为按语言定义,再针对性覆盖 "editor.autoClosingBrackets": "languageDefined", "editor.autoClosingTags": "languageDefined", "editor.language.customizations": { // 保留XML/HTML类文件的自动补全 "[xml]": { "editor.autoClosingBrackets": "always", "editor.autoClosingTags": true }, "[html]": { "editor.autoClosingBrackets": "always", "editor.autoClosingTags": true }, "[xhtml]": { "editor.autoClosingBrackets": "always", "editor.autoClosingTags": true }, // 禁用其他文件类型的<自动补全> "[cpp]": { "editor.autoClosingBrackets": "never", "editor.autoClosingTags": false }, "[c]": { "editor.autoClosingBrackets": "never", "editor.autoClosingTags": false }, "[csv]": { "editor.autoClosingBrackets": "never", "editor.autoClosingTags": false }, "[h]": { "editor.autoClosingBrackets": "never", "editor.autoClosingTags": false }, // 可继续添加需要禁用的文件类型,比如[python]、[javascript]等 }
3. 验证效果
保存配置后重启VS Code,测试cpp、h、CSV等文件输入<时的行为——此时应该不会自动补全>;XML/HTML文件则正常保留标签自动闭合功能。
关键说明
editor.autoClosingBrackets控制尖括号、括号等符号的自动配对,never会完全禁用该语言下的自动配对行为。editor.autoClosingTags专门针对HTML/XML标签的自动闭合,确保这类文件的编辑体验不受影响。
内容的提问来源于stack exchange,提问作者Wolf-Kun
相关产品推荐
相关产品推荐

