难免有这样的场景需要在编辑代码的时候小范围地移动光标,笔者在别的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" }, ]