Search code examples
visual-studio-codekeyboard-shortcutsvscode-git

VSCode keyboard shortcut: stage selected files


I have a laptop with a sometimes-flakey trackpad, and so I often disable it since I can do most navigation with the keyboard anyways. There is a feature in VSCode that I use when I have a mouse/trackpad that is very useful. In the Source Control panel, I can select multiple files, then click the plus sign for "stage" to stage the selected files, while leaving the unselected files behind. This helps me review my changes in manageable batches, and see what is left to review.

stage changes button

I have found that it is possible to stage all files through command palette (>Git: Stage All Changes) and through keyboard shortcut (git.stageAll), but I like to review my files before staging them, and rarely want to stage ALL of them at once.

I've also found it's possible to stage an individual file by keyboard shortcut, and have set up a command like this in keybindings.json:

    {
        "key": "ctrl+enter",
        "command": "git.stage",
        "when": "focusedView == workbench.scm"
    }

However, the problem with this is that it only works on a single file at a time. Sometimes I want to select multiple files at once to stage -- today's example of this were some brand-new tests I had written and were ready to stage all together, but I wanted to review any other changes separately before staging those. I could go one-by-one through these, but that is tedious, and it's much better if I could do what I am already used to doing with a mouse, and what hitting the plus button does.

I also found this setup:

    {
        "key": "ctrl+enter",
        "command": "git.stageSelectedRanges",
        "when": "focusedView == workbench.scm"
    }

Which does stage changes from multiple files, but it leaves the filenames behind in the unstaged changes area, which gets in the way when I am trying to figure out what else needs to be reviewed for staging.

I realize this is pretty picky, and my worst-case scenario would be to use the tab and arrow keys to navigate to the existing plus button to get the behavior I want. But it would be nice if I could have a keyboard shortcut that did the same thing, especially since that functionality appears to already exist in this button.


Solution

  • This is a known issue tracked by SCM: Support keyboard shortcuts #24916. I suggest that you give that issue ticket a thumbs up to show support for it. You can also subscribe to it to get notified about discussion and progress. Please avoid making noisy comments there like ones that just consist of "+1" / "bump".