Luca
Luca

Reputation: 363

VS Code: How to set that when I press CTRL + UP or DOWN arrow, the cursor move with the page?

My problem is that when I press CTRL + up or down arrow, the cursor doesn't move when it reaches the border of the page, and therefore when I release the CTRL button, the page "bumps" to where the cursor is.

Is it possible to change this behaviour?

For example in Visual Studio IDE, the cursor is "anchored" to the top of the page if you press CTRL + down arrow.

Thanks in advance.

Upvotes: 16

Views: 5251

Answers (2)

AshF
AshF

Reputation: 235

There is a workaround.

Edit your keybinding.json and add this:

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

Upvotes: 21

Fenistil
Fenistil

Reputation: 3801

If you wanted to keep the cursor where it was on the screen, you can do the followings:

  1. First install the multi-command extension to VSCode.

  2. Open your the settings JSON and paste these commands into it:

     "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. Open your keyboard shortcuts JSON and paste the followings into it:

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

Save the files, you're done. :)

Upvotes: 0

Related Questions