【问题标题】:vscode: How to set that when I press CTRL + up or down arrow, the cursor move with the page?vscode:如何设置当我按CTRL +向上或向下箭头时,光标随页面移动?
【发布时间】:2018-04-24 08:41:18
【问题描述】:

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

是否可以改变这种行为?例如,在 Visual Studio 中,如果您按下 CTRL + down 箭头,光标将“锚定”到页面顶部。

提前致谢

【问题讨论】:

    标签: visual-studio-code vscode-settings


    【解决方案1】:

    有一个解决方法。编辑你的 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
        }
    }
    

    【讨论】:

    • 太棒了!它确实像一个魅力!只有一个问题...要做到这一点,我必须手动转到我的设置目录并搜索文件...有没有办法像在用户设置中那样在 vscode 中编辑文件?
    • @Luca:如果你去Keyboard Shortcuts右上角是一个图标来编辑json文件。
    • VS Community 19 是否有类似的解决方法?我想要与 OP 想要的相反——在我的 VS 社区中拥有默认的 VS Code 行为
    • 嗨@AshF。你知道这个答案是否仍然有效?我已将此 sn-p 添加到 keybindins.json,但我的光标仍然没有随 ctrl+up/down 移动。我正在运行 VSCode v1.60.0。
    • @cag8f 是的,它仍然有效。我刚刚尝试从我的 keybindings.json 中删除这些行,光标现在离开了屏幕。确保将它们添加到 .json 的末尾,以防有其他东西覆盖它们。
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      相关资源
      最近更新 更多