You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现切换至SCM时自动聚焦提交消息文本框?

Absolutely! You can make VS Code automatically focus the commit message text box whenever you open the SCM panel—here are two straightforward ways to set this up, covering both keyboard shortcuts and mouse clicks:

Solution 1: Use VS Code's Built-in Setting (Easiest)

VS Code has a native setting made exactly for this scenario—no custom code required!

  • Open your VS Code settings: Press Ctrl+, (Windows/Linux) or Cmd+, (Mac), or go to File > Preferences > Settings
  • In the search bar, type scm focus commit message
  • Look for the setting labeled SCM: Focus Commit Message On Open and check the box next to it

That's all! Now whenever you open the SCM panel—whether by clicking the SCM icon in the activity bar or using the Ctrl+Shift+G shortcut—the commit message text box will automatically get focus.

Solution 2: Custom Keyboard Shortcut (For Fine-Grained Control)

If you want more control over the behavior (like only triggering this for the keyboard shortcut), you can chain the "open SCM" and "focus commit box" commands in your keybindings:

  1. Open the keyboard shortcuts JSON file: Press Ctrl+K Ctrl+S to open the shortcuts UI, then click the curly braces {} icon in the top-right corner
  2. Add the following configuration to the file:
{
  "key": "ctrl+shift+g",
  "command": "runCommands",
  "args": {
    "commands": [
      "workbench.view.scm",
      "scm.inputBox.focus"
    ]
  },
  "when": "!scmVisible"
}
  • The runCommands action executes both commands in sequence: first it opens the SCM panel, then it focuses the commit message input
  • The when clause ensures this only runs when the SCM panel isn't already open, so you don't accidentally refocus the input if the panel is already visible

Either method will solve your problem perfectly. The built-in setting is the quickest way to cover all cases (mouse and keyboard), while the custom shortcut gives you extra flexibility if you need it.

内容的提问来源于stack exchange,提问作者solr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:54:01