There is a Stage Selected Lines
button for Git, but is there a way to add a keyboard shortcut for it?
It is too much trouble having to click twice (three dots
> Stage Selected Lines
).
All keyboard shortcuts in VS Code can be customized via the keybindings. json file. To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and select the Open Keyboard Shortcuts (JSON) button on the right of the editor title bar. This will open your keybindings.
Select the lines you want and then press: Windows: Shift + Alt + i. Mac: shift + option + i.
Navigate to a Specific Line Note: To go to a line in the file, you use ctrl + g, then type a line number. Alternatively, you can also open the go-to file menu with command + p first.
In case anyone is still looking for this:
The commands stageSelectedRanges
, unstageSelectedRanges
, revertSelectedRanges
have been introduced a while ago. Note that there is currently a related bug in VSCode: the diff view does not refresh after a partial stage - but apart from that it works like a charm.
This is how I set it up in my keybindings:
{
"key": "s",
"command": "git.stageSelectedRanges",
"when": "isInDiffEditor && editorTextFocus"
},
{
"key": "u",
"command": "git.unstageSelectedRanges",
"when": "isInDiffEditor && editorTextFocus"
},
{
"key": "r",
"command": "git.revertSelectedRanges",
"when": "isInDiffEditor && editorTextFocus"
}
The accepted answer didn't work for me so I raised a ticket on GitHub:
When condition for Source Control View for better keybindings #99683
The following did:
{
"key": "ctrl+a",
"command": "git.stageAll",
"when": "sideBarFocus && activeViewlet == 'workbench.view.scm'"
},
{
"key": "ctrl+s",
"command": "git.stage",
"when": "sideBarFocus && activeViewlet == 'workbench.view.scm'"
},
{
"key": "ctrl+u",
"command": "git.unstage",
"when": "sideBarFocus && activeViewlet == 'workbench.view.scm'"
},
UPDATE:
I was also able to get single keys working via the addition of the listFocus
attribute:
{
"key": "s",
"command": "git.stage",
"when": "listFocus && sideBarFocus && activeViewlet == 'workbench.view.scm'"
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With