Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code scroll up/down moving the cursor

When scrolling down in VSCode. Using arrow keys makes you have the cursor on the bottom. I can use Ctrl + Arrow Down This scrolls the screen and the cursor keeps its position. In this case I need to click on the new line in order to start editing. However I'm looking for a way to scroll and move the cursor. For example if I'm in the middle of the screen I want to scroll and get the cursor to maintain its relative position in the middle.

Has anyone done this?

like image 928
loki Avatar asked Jul 18 '26 19:07

loki


1 Answers

With the help of the extension Multi Command

Add this setting

  "multiCommand.commands": [
    {
      "command": "multiCommand.up1LineKeepCursor",
      "sequence": [
        {"command": "editorScroll", "args": {"to": "up", "by": "line" }},
        "cursorUp"
      ]
    },
    {
      "command": "multiCommand.down1LineKeepCursor",
      "sequence": [
        {"command": "editorScroll", "args": {"to": "down", "by": "line" }},
        "cursorDown"
      ]
    }
  ]

And these keybindings

  {
    "key": "shift+ctrl+alt+up",
    "command": "multiCommand.up1LineKeepCursor",
    "when": "editorTextFocus"
  },
  {
    "key": "shift+ctrl+alt+down",
    "command": "multiCommand.down1LineKeepCursor",
    "when": "editorTextFocus"
  }

You can use any key binding you like.

It works good when Word Wrap is OFF.

like image 174
rioV8 Avatar answered Jul 21 '26 17:07

rioV8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!