難免有這樣的場景需要在編輯代碼的時候小范圍地移動光標,筆者在別的ide的習慣是通過“alt + jkli”
來實現光標移動,網上搜VS Code快捷鍵設置基本只能找到改默認值的方法,而沒有能設置 相同的操作同時有多個快捷鍵的方法
廢話少說,進入正題
首先打開快捷鍵設置
錄制按鍵,按下“右鍵”,來查找相關快捷鍵,箭頭所指為要找的(編輯時的光標移動)
右鍵更改鍵綁定,改為 alt+l
,若沖突,可以視情況把沖突的快捷鍵改成別的(比如已經存在alt+l
,則把它改為ctrl+alt+l
)
更改完之后,點擊右上角的以JSON格式打開,會打開keybinding.json
文件
會形成類似這樣的json
原來的right
鍵的command前面加上了-
號來"消除"此快捷方式,那么同理,去掉這個負號就可以“生效”了
去掉后發現就可以實現同樣的快捷操作可以有多種快捷鍵
其他方向鍵類似,讀者可以自行實現
最后附上我的keybinding.json
// 將鍵綁定放在此文件中以覆蓋默認值auto[] [ { "key": "alt+i", "command": "cursorUp", "when": "textInputFocus" }, { "key": "up", "command": "cursorUp", "when": "textInputFocus" }, { "key": "alt+k", "command": "cursorDown", "when": "textInputFocus" }, { "key": "down", "command": "cursorDown", "when": "textInputFocus" }, { "key": "alt+j", "command": "cursorLeft", "when": "textInputFocus" }, { "key": "left", "command": "cursorLeft", "when": "textInputFocus" }, { "key": "alt+l", "command": "cursorRight", "when": "textInputFocus" }, { "key": "right", "command": "cursorRight", "when": "textInputFocus" }, { "key": "down", "command": "list.focusDown", "when": "listFocus && !inputFocus" }, { "key": "down", "command": "selectNextSuggestion", "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus" }, { "key": "alt+k", "command": "selectNextSuggestion", "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus" }, { "key": "up", "command": "selectPrevSuggestion", "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus" }, { "key": "alt+i", "command": "selectPrevSuggestion", "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus" }, ]