3

By default, Ctrl+PageUp and Ctrl+PageDown combinations in Visual Studio Code switch view to the next/previous tab. I would like to reconfigure them so they work like in Visual Studio, so they navigate to the top/bottom of the screen.

I am trying to modify the editor's keybindings (keybindings.json) but I find myself unable to find proper commands.

So far, I have found:

  • cursorTop/cursorBottom - moves cursor to the top/bottom of the whole file
  • scrollLineUp/scrollLineDown - scrolls the view, but does not change cursor's position
  • scrollPageDown/scrollPageUp - moves the view one page down/up, but does not change the cursor's position

I have tried Visual Studio Keymap (https://marketplace.visualstudio.com/items?itemName=ms-vscode.vs-keybindings) extension, but it also does not provide the required functionality.

rs232
  • 1,248
  • 8
  • 16

1 Answers1

6

Of course, almost immediately after posting a question I've stumbled upon a solution. This issue comments (https://github.com/Microsoft/vscode/issues/15058) gave me a hint, so I tried cursorMove command with "to": "viewPortTop" and "to": "viewPortBottom" arguments and, surprisingly, it worked.

The complete json to be added to keybindings.json is:

{
    "key": "ctrl+pageup",
    "command": "cursorMove",
    "when": "editorTextFocus",
    "args": {
        "to": "viewPortTop"
    }
}    ,
{
    "key": "ctrl+pagedown",
    "command": "cursorMove",
    "when": "editorTextFocus",
    "args": {
        "to": "viewPortBottom"
    }
}    
rs232
  • 1,248
  • 8
  • 16
  • For interesting things you can do with cursorMove and select, see https://stackoverflow.com/questions/50838602/bind-a-keypress-to-a-shell-command-that-uses-the-current-file-in-visual-studio-c/50846586#50846586 [type and select text to run in terminal]. – Mark Jul 27 '18 at 15:26
  • With Ctrl+PgDown this also scrolls the editor one line down. Probably because the last partially visible line is selected instead of the last fully visible line. Do you know how to fix this? – ygoe Oct 08 '21 at 20:13
  • 1
    See, the same happens to me, too. The `"to": "viewPortBottom"` parameter needs an additional `"value": 2` to avoid the downscrolling. It might not move the cursor the the very last line in all cases, but it shouldn't scroll. Moving to the top doesn't need this, it always jumps to the first fully visible line. They probably only consider a line's top position, not both top and bottom. – ygoe Oct 08 '21 at 20:27