Skip to content

Add keybinding to focus secondary main view#5663

Open
blmerrett1 wants to merge 2 commits into
jesseduffield:masterfrom
blmerrett1:feat/focus-secondary-view-keybinding
Open

Add keybinding to focus secondary main view#5663
blmerrett1 wants to merge 2 commits into
jesseduffield:masterfrom
blmerrett1:feat/focus-secondary-view-keybinding

Conversation

@blmerrett1
Copy link
Copy Markdown

@blmerrett1 blmerrett1 commented May 31, 2026

PR Description

Adds a focusSecondaryView keybinding (default 9) to focus the secondary main view directly, mirroring the existing focusMainView (0). 0 focuses the primary main view and 9 the secondar, forming a natural pair, adjacent on the number row. The secondary panel title shows [9] when showPanelJumps is enabled, and the binding is configurable via keybinding.universal.focusSecondaryView.

Motivation: Jump straight to staged

Reaching the secondary main view (for example the staged diff of a partially-staged file) otherwise takes multiple key presses, whereas the primary already has a direct key. While using lazygit I often found myself wanting to jump straight to staged changes. Beyond just staged vs unstaged, the pattern is also extensible to any lazygit view with a primary and secondary panel.

Fix: Main View

The first commit is a small, separable pre-existing fix: SwitchToFocusedMainViewController was only attached to the side panels, so the focus-main-view key (0) did nothing once a main view itself was focused. The keybinding still appears in the view title, so it seemed reasonable that it would still move focus. Attaching it to the Normal/NormalSecondary contexts makes 0 (and the new 9) work from within the main view, e.g. returning to the primary from the secondary. I isolated this change to its own commit with its own regression test.

Testing

Integration tests added for both the fix (focus the primary from the secondary via the keybinding) and the feature(focus the secondary from a side panel, switch between the two main views, and no-op when no secondary view is visible). Manually verified with showPanelJumps on and off, with a custom key, and with <disabled>. Keybinding tips page also verified.

Requirements Check:

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted
  • Tests have been added/updated
  • Text is internationalised
  • If a new UserConfig entry was added, make sure it can be hot-reloaded
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@blmerrett1 blmerrett1 force-pushed the feat/focus-secondary-view-keybinding branch from 916ea37 to ce3cfae Compare May 31, 2026 14:16
@blmerrett1
Copy link
Copy Markdown
Author

Hi @jesseduffield ,
I'm a big fan of lazygit, and it's become my absolute main git driver.
I found myself wanting to jump straight to the staged changes panel, and thought it would be good to try and contribute. I implemented and have been using for a while now, so seemed right to try and share.
Adding 9 felt like a neat solution for the secondary view, giving me the (0,9) pair on the keyboard for (primary, secondary). It led me to a small fix making sure the number keys still worked once the primary or secondary views were focussed.
I've tried to follow the repo's conventions as much as possible, but let me know if anything is out of place, and I would welcome your feedback on the change itself.
Thanks so much :)
Ben

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant