You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VS Code中禁用ASP.NET Razor Pages的输入建议?

解决VS Code中Razor文件自动接受输入建议的问题

以下是几种有效的解决方案,按优先级尝试:

1. 移除空格作为补全提交字符

问题的核心可能是VS Code默认将空格键设为接受补全建议的提交字符,即使关闭了快速建议,这个设置仍会生效。针对Razor文件单独配置:
打开settings.json,添加以下配置:

"[aspnetcorerazor]": {
    "editor.acceptSuggestionOnCommitCharacter": false,
    "editor.quickSuggestions": {
        "other": "off",
        "comments": "off",
        "strings": "off"
    }
}

如果只想移除空格而保留其他提交字符(比如=、.),可以更精确地配置提交字符列表:

"[aspnetcorerazor]": {
    "editor.commitCharacters": [
        "=", ".", ",", ";", "(", ")", "[", "]", "{", "}", "+", "-", "*", "/", "%", "&", "|", "^", "!", "~", "<", ">", "?", ":"
    ],
    "editor.quickSuggestions": {
        "other": "off",
        "comments": "off",
        "strings": "off"
    }
}

2. 调整C#扩展的相关设置

因为Razor文件依赖C#语言服务,可能C#的快速建议设置在起作用,添加以下配置到settings.json:

"[csharp]": {
    "editor.quickSuggestions": {
        "other": "off",
        "comments": "off",
        "strings": "off"
    },
    "editor.acceptSuggestionOnCommitCharacter": false
}

3. 禁用特定的补全提供者

如果上述方法无效,可以尝试禁用Razor或C#的补全提供者。按Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac)打开命令面板,输入Preferences: Configure Language Specific Settings,选择aspnetcorerazor,然后添加:

"[aspnetcorerazor]": {
    "editor.suggest.showWords": false,
    "editor.suggest.showKeywords": false,
    "editor.suggest.showMethods": false,
    // 根据需要禁用其他类型的补全
}

完成配置后重启VS Code,验证问题是否解决。

内容的提问来源于stack exchange,提问作者Eric Eskildsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 14:54:56