vscode: 如何设置按CTRL + 向上或向下箭头时,光标随页面移动?

vscode: How to set that when I press CTRL + up or down arrow, the cursor move with the page?

我的问题是,当我按下 CTRL + updown 箭头时,光标到达页面边界时不会移动,因此当我释放 CTRL 按钮时,页面 "bumps" 到光标所在的位置。

是否可以改变这种行为?例如在 Visual Studio 中,如果按 CTRL + down 箭头,则光标 "anchored" 到页面顶部.

提前致谢

有一个解决方法。编辑您的 keybinding.json 并添加这个...

{
    "key": "ctrl+up",
    "command": "editorScroll",
    "when": "editorTextFocus",
    "args": 
    {
        "to": "up",
        "by": "line",
        "revealCursor": true
    }
},
{
    "key": "ctrl+down",
    "command": "editorScroll",
    "when": "editorTextFocus",
    "args": 
    {
        "to": "down",
        "by": "line",
        "revealCursor": true
    }
}

如果您想将光标保持在屏幕上的原处,可以执行以下操作:

  1. 首先将 multi-command 扩展安装到 VSCode。

  2. 打开设置 JSON 并将这些命令粘贴到其中:

     "multiCommand.commands": [
     {
         "command": "multiCommand.keepCursorPosScrollUp",
         "sequence": [
             {
                 "command": "editorScroll",
                 "args":{
                     "to": "up",
                     "by": "line",
                     "revealCursor": false
                 }
             },
             "cursorUp"
         ]
     },
     {
         "command": "multiCommand.keepCursorPosScrollDown",
         "sequence": [
             {
                 "command": "editorScroll",
                 "args":{
                     "to": "down",
                     "by": "line",
                     "revealCursor": false
                 }
             },
             "cursorDown"
         ]
     }
    

    ]

  3. 打开键盘快捷键 JSON 并将以下内容粘贴到其中:

     {
         "key": "ctrl+up",
         "command": "extension.multiCommand.execute",
         "args": {
             "command": "multiCommand.keepCursorPosScrollUp"
         },
         "when": "editorTextFocus"
     },
     {
         "key": "ctrl+down",
         "command": "extension.multiCommand.execute",
         "args": {
             "command": "multiCommand.keepCursorPosScrollDown"
         },
         "when": "editorTextFocus"
     }
    

保存文件,大功告成。 :)