VS Code 设置双快捷键(快速移动光标)

本文已同步到https://www.aukocharlie.com/archives/vscode%E8%AE%BE%E7%BD%AE%E5%8F%8C%E5%BF%AB%E6%8D%B7%E9%94%AE

 

平时写代码会经常用到上下左右键,比如打出两个括号 () ,编辑完之后得按到右括号后面

 

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

  

 

posted @ 2019-10-15 14:37  aukocharlie  阅读(9670)  评论(0编辑  收藏  举报