13

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.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Luca
  • 333
  • 2
  • 13

2 Answers2

18

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
    }
}
informatik01
  • 16,038
  • 10
  • 74
  • 104
AshF
  • 205
  • 2
  • 6
  • Fantastic! It did work like a charm! Only one question... to do it I had to manually go to my settings dir and search the file... Is there a way to edit the file within vscode like you do for user settings? – Luca Apr 24 '18 at 14:22
  • @Luca: If you go to the `Keyboard Shortcuts` in the top right is an icon to edit the `json` file. – rioV8 Aug 09 '19 at 21:41
  • Is there a similar workaround possible for VS Community 19? I want the opposite to what OP wants - to have the default VS Code behavior in my VS Community – pun11 Mar 10 '21 at 11:29
  • Hi @AshF. Do you know if this answer is still valid? I've added this snippet to keybindins.json, but my cursor still does not move with ctrl+up/down. I'm running VSCode v1.60.0. – cag8f Sep 08 '21 at 03:59
  • @cag8f Yes, it's still valid. I've just tried removing those lines from my keybindings.json and the cursor now goes offscreen. Make sure that you add them at the end of the .json incase something else is overriding them. – AshF Sep 24 '21 at 18:04
0

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. :)

Fenistil
  • 3,734
  • 1
  • 27
  • 31