2

In VS Code, when the source control view is focused, I want to focus the first file in "staged Changes", navigate and focus between them, is there a keyboard shortcut to do this?

I want the behavior works like "Search: Focus Next Search Result,Search: Focus Previous Search Result". but in source view stage section

Here's a screenshot of what I'm talking about: screenshot of source control view with an arrow pointing to first entry

2

2 Answers 2

1

You can do this directly from anywhere in the scm view, but you will need a macro extension like Multi-Command. And this keybinding:

{ "key": "alt+u", // whatever keybinding you want "command": "extension.multiCommand.execute", "args": { "sequence": [ "list.focusFirst", // focuses the commit message input, as close as you can get "list.focusDown", "list.focusDown", "list.focusDown", "list.select" // add this to also open the scm diff ], }, "when": "focusedView == workbench.scm" } 

When you are focused in the scm view you could go down/up a file and focus it with this keybinding:

 { "key": "alt+down", // whatever keybinding you want "command": "extension.multiCommand.execute", "args": { "sequence": [ "list.focusDown", // or "list.focusUp" "list.select" ], }, "when": "focusedView == workbench.scm" } 

To open the next item in the scm view and return focus to that scm view, try this keybinding:

{ "key": "alt+down", // whatever keybinding you want "command": "extension.multiCommand.execute", "args": { "interval": 400, // need a delay "sequence": [ "list.focusDown", "list.select", "workbench.action.focusSideBar", ], }, "when": "focusedView == workbench.scm" } 
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, this works,but If I want to navigate between these files and focus, work like "search.action.focusNextSearchResult" how to make this multicommand?
Can you explain a little more the sequence of what you want to do - I don't quite follow.
I edited the answer if what you want to do is focus the first file and focus that file in an editor.
(up){ "sequence": [ "workbench.scm.focus", "list.focusUp", "list.select" ] }, (down){ "sequence": [ "workbench.scm.focus", "list.focusDown", "list.select" ] }, (focus first){ "sequence": [ "workbench.scm.focus", "list.focusFirst", "list.focusDown", "list.focusDown", "list.focusDown", "list.select" ] }
thank you, now I'm using three shortcut(up,down, focusfirst) to control this If the selected list is above the first change file, I want the shortcut(up or down) to focus the first change file directly. so I hope I can navigate only use two shortcut(up and down), Is there a way to do that? (i think it relate to the “when” condition ,When the focused item is above the first)
|
0

This is pretty easy and fast with regular keyboard navigation.

You can switch to the source control pane with the View: Show Source Control command, or the corresponding ctrl+shift+g shortcut. Or if it's already the current tab of the sidebar and the sidebar is not focused, focus it with ctrl+0. See also How can I navigate and manipulate list views in VS Code using the keyboard?.

Once you have focused on the source control view, just press up or down until you reach it.

If the listing is not focused yet, and something else like the commit message input or commit button is focused instead, just press tab or shift+tab until it is. Ex. if the commit message input is focused, you should be able to just press shift+tab.

1 Comment

This works for me, it is a little fiddly as after getting focus on the source control pane, you typically start with the commit message field selected. To get to the files then requires Tab, Tab, followed by a few down arrows. Not too bad once you have got used to it I guess.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.