Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep VS Code cursor on screen

How can I keep the text cursor (caret) on the screen when scrolling in VS Code with Ctrl + up/down?

I've searched for scroll options, text options, extensions, etc. To no avail.

like image 564
Matt W Avatar asked Apr 10 '26 15:04

Matt W


2 Answers

This is what I'm using in keybindings.json and it pretty much matches Visual Studio's Ctrl+Up/Down behaviour. (ie: basically SebastianDB's answer but for both keys and line up/down instead of page. Also, you don't need the macros extension, it works out of the box).

    {
        "key": "ctrl+up",
        "command": "editorScroll",
        "args": {
            "to": "up",
            "by": "line",
            "revealCursor": true
        },
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+down",
        "command": "editorScroll",
        "args": {
            "to": "down",
            "by": "line",
            "revealCursor": true
        },
        "when": "editorTextFocus"
    }    
like image 121
Brad Robinson Avatar answered Apr 14 '26 02:04

Brad Robinson


I haven't tried this myself but have you looked at this yet?

Install this:

https://marketplace.visualstudio.com/items?itemName=geddski.macros

then add a macro to ctrl+up/down with this sample and change the key from alt+pageup to what you want.

https://github.com/Microsoft/vscode/issues/22796

{
    "key": "alt+pageup",
    "command": "editorScroll",
    "args": {
        "to": "up",
        "by": "page",
        "revealCursor": true
    },
    "when": "editorTextFocus"
}

Hope it works, have a good one!

like image 30
SebastianDB Avatar answered Apr 14 '26 00:04

SebastianDB



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!