最近 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"
}
]
保存一下,搞定。

