配置 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"
    }
]

保存一下,搞定。

posted @ 2016-04-20 18:30  DiryBoy  阅读(4282)  评论(0编辑  收藏  举报