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"
    },
]

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM