配置 VSCode 使之不只用 Tab 跟回车键确认输入一个智能提示项

最近 VSCode 终于推出 1.0 正式版了。下载安装之后,发现默认只能用 Tab 跟回车来确认输入一个智能提示项,这用惯 Visual Studio C# 的我感到无比痛苦。

然而,在 VSCode 里面,连配置快捷键都是用代码的,json 格式,找不到像 VS 里面类似下面的那种选项:

Option of "Only use Tab or Enter to commit"

网上搜了一轮,只找到问同样的问题的人而没有答案,只好自己慢慢挖掘了。经过千辛万苦,最后发现在默认的 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"
    }
]

保存一下,搞定。

转载于:https://www.cnblogs.com/Diryboy/articles/Workaround-VSCode-Use-only-Tab-or-Enter-to-commit.html

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值