26

Is there any way to focus to this input by keyboard rather than mouse click in Visual Studio Code?

Screenshot of VS Code showing the commit message box

2
  • 3
    There was a vscode issue specifically for this that was closed in 2018. However, the final comment mentioned Ctrl + Shift + G, which is currently the default keybinding for Show Source Control—not the commit message specifically—so it is not a solution. Commented May 28, 2021 at 17:05
  • 2
    Looks like github.com/microsoft/vscode/issues/125784 is the new issue. Seems like it's supposed to focus when you open the source control view, but doesn't at the moment. Commented Sep 14, 2021 at 2:40

8 Answers 8

9

While certainly not ideal, I've found the following will focus the Source Control Message input field:

  • ctrl shift G
  • then, ESC
  • then, Tab

Now when you repeat ctrl shift G it seems to focus the input directly.

2
  • how funny, in my case I needed ctrl + shift + g and g, then esc, then tab twice, I have version 1.88.1 and commit e170252f762678dec6ca2cc69aba1570769a5d39, I think gitlens is overwriting default keyboard shortcuts
    – manus
    Commented May 2 at 3:14
  • Setting Gitlens: Keymap to none will revert that. Commented Jun 12 at 16:41
6

As a workaround, we can use the extension multi.

Define shortcut like:

    {
        "key": "escape",
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                "list.focusFirst",
                "list.select",
            ]
        },
        "when": "listFocus && workbench.scm.active",
    },
5

For users of GitLens extension with the default "gitlens.keymap": "chorded" setting:

If you are in any section in the left menu other than Source Control (e.g. Explorer or Extensions, then use Ctrl+Shift+G then press G again

If you are already in the Source Control section of the left menu, then use Tab or Shift+Tab to move focus forward or backward (respectively)

3
  • 1
    What's pressing G again supposed to do? For me it searches the changed files.
    – wjandrea
    Commented Jul 23, 2022 at 19:00
  • 5
    The 2nd G brings me to the Source Control section. After the Ctrl + Shift + G, it only says at the bottom of VS Code the following: "Waiting for second key of chord". In hindsight, I think the 2nd G is needed for me because I have the extension GitLens installed.
    – Jesse
    Commented Aug 19, 2022 at 17:27
  • 1
    @Jesse yeah, there's a workaround for that posted here: github.com/gitkraken/vscode-gitlens/issues/…
    – Jeremy
    Commented Jul 13, 2023 at 2:38
5

Apparently, according a VS Code maintainer, Ladislou Szomoru (source), ctrl+shift+g (workbench.view.scm) should open the Source Control View and focus the commit message input, but there's a known bug that prevents that from happening which should be fixed in the September 2023 release. See regression: ctrl+shift+g doesn't focus source control anymore when invoked for the first time #184155 (should be fixed in the May 2024 release).


For versions of VS Code affected by the above mentioned bug, I have an improved version of Mark's single-keyboard-shortcut answer that also supports when there are multiple open repositories and uses the new runCommands feature instead of the multi-command extension:

{
    "key": "", // TODO
    "command": "runCommands",
    "args": {
        "commands": [
            "workbench.scm.focus",
            "list.focusFirst",
            "list.focusDown",
            // ^ with multiple repositories, there is an additional level of
            //   list nesting for separating by repository. this is to skip
            //   that collapse handle / parent list item
            "list.select",
        ],
    },
    "when": "gitOpenRepositoryCount >= 1",
},
{
    "key": "", // TODO can put the same thing as above
    "command": "runCommands",
    "args": {
        "commands": [
            "workbench.scm.focus",
            "list.focusFirst",
            "list.select",
        ],
    },
    "when": "gitOpenRepositoryCount == 1",
},
2

UPDATE: There are two new commands which should be in vscode v1.90 early June 2024:

workbench.scm.action.focusNextInput

workbench.scm.action.focusPreviousInput

See Commit. They appear to be unbound to any keybinding by default and they don't show up in the Command Palette for me but they are in the Keyboard Shortcuts editor so you can make keybindings for them there.

workbench.scm.action.focusNextInput will work if there is only one commit message box as well as there are more than one.

Both commands will loop through multiple repositories in the same workspace.


Okay, adding my answer found in the following issue, slightly modified:

Ensure that scm.focus command works in all cases

Use this keybinding:

{
  "key": "alt+e",             // whatever keybinding you want
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "workbench.scm.focus",
      "list.focusFirst",
      "list.select"
    ]
  },
}

and the macro extension multi-command.

This works whether the scm view is open or not, whether something is already focussed in the scm view or whether a text editor is focussed.

So just the one keybinding, no need to Home and Enter whether a scm file has focus or not.

1

First, if needed, focus Source Control with Ctrl+Shift+G.

Press Home to focus the message box and Enter or Tab or Space to start typing in it.

Thanks to yellowtailfan for bringing this up on GitHub. They specifically said "if one of the changed files has focus", but I don't think that's crucial for Home Enter to work.


Overall, you can navigate the whole Source Control panel like this using direction keys (Up, Down, etc.), which means you can select files, use Left/Right to show/hide sections like "Staged Changes", and access more commit options by highlighting that box then using Tab to move inside it.

1
  • 1
    In a previous issue, ArturoDent said "Home" and "Enter" would work when a file has focus in the scm view. github.com/microsoft/vscode/issues/…. That guy is brilliant. See his revised answer below.
    – Mark
    Commented Jul 23, 2022 at 21:58
0

You can use TAB/SHIFT+TAB key to move focus in left SOURCE CONTROL panel.

For some color theme you can easily notice where the focus is.

Most of the time the focus is located on the file names in Changes pane(?). In that case press SHIFT+TAB key to move focus to Message field.

-4

Keyboard Shortcuts: "Source control:Focus on Source Control View"

1
  • 4
    That goes to source control, but not to the message. Commented Mar 16, 2021 at 12:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.