配置 VSCode 使之不只用 Tab 跟回车键确认输入一个智能提示项
最近 VSCode 终于推出 1.0 正式版了。下载安装之后,发现默认只能用 Tab 跟回车来确认输入一个智能提示项,这用惯 Visual Studio C# 的我感到无比痛苦。
然而,在 VSCode 里面,连配置快捷键都是用代码的,json 格式,找不到像 VS 里面类似下面的那种选项:
网上搜了一轮,只找到问同样的问题的人而没有答案,只好自己慢慢挖掘了。经过千辛万苦,最后发现在默认的 keybindings.json 配置文件几乎最下方找到了线索:
{ "key": ".", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'typescript' && suggestionSupportsAcceptOnKey" },
这就是在说,在编辑器中用户按了 “.” 之后,如果 when 后面的条件成立,那么就执行 “^接受所选的建议项”,前面的 “^” 是指,接受的建议项应该加在用户敲的 “.” 之前。打个比方,当用户输入 ab.(注意最后的点),而此时建议项是 abc,那么最终结果是 abc.
明白这个以后,就可以将一大堆可接受 commit character 的配置成这样了,最终我的 keybindings.json 长这样:
// Place your key bindings in this file to overwrite the defaults [ { "key": "shift+9", // ( "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+0", // ) "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+,", // < "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+.", // > "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "[", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "]", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "space", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": ",", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+;", // : "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+/", // ? "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": ";", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "=", "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "numpad_add", // + "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+=", // + "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+8", // * "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "numpad_multiply", // * "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "-", // - "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "numpad_subtract", // - "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "/", // / "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "numpad_divide", // / "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+7", // & "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" }, { "key": "shift+\\", // | "command": "^acceptSelectedSuggestion", "when": "editorTextFocus && suggestWidgetVisible && suggestionSupportsAcceptOnKey" } ]
保存一下,搞定。
- DiryBoy
http://DiryBoy.cnblogs.com
http://DiryBoy.cnblogs.com
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述