Skip to content

Add g? key help and describe every mapping - #24

Merged
CoreyKaylor merged 1 commit into
mainfrom
keymap-help
Nov 5, 2026
Merged

CoreyKaylor merged 1 commit into
mainfrom
keymap-help

Conversation

@CoreyKaylor

Copy link
Copy Markdown
Owner

Fixes #21.

Stacked on #23 (it builds on q, gzp, and close_key). Merge #23 first; this PR then retargets to main.

What changes for users

  • g? in every DiffBandit window opens a floating list of that window's keys, grouped by purpose: General, Navigation, Hunks, Files, Staging and actions, Merge, Layout, Panel, Commit, Folder, Log. Keys that do the same thing share a row (<CR>, o). q, <Esc>, or g? closes it, and so does leaving the window.
  • The list is read from the buffer's live mappings, so remapped or disabled keys show as they really are.
  • Each view explains what it shows:
    • The diff explains its compact header: all/unstg/stg, 2/6, h3/5, M A D R ??, 1/5.
    • The panel explains the staged symbols.
    • The commit message window and the merge result list :w.
    • Every help window points at :DiffBanditClose and :help diffbandit.
  • Visible hints. A muted g? help appears at the right of the diff, merge, and folder headers, on the panel's first row, and in the git log header. The commit label now reads Commit message: :w commit <Space> amend. When a header is too narrow, the hint is dropped and the path stays.
  • Every mapping has a description (DiffBandit: Next hunk), so which-key, :map, and keymap pickers can explain it.
  • The review hint line is built from the configured keys. It used to be a hardcoded string in three places.
  • New config: navigation.help_key = "g?". Set it to false to remove both the key and the hints.

Implementation

  • lua/diffbandit/util/keyhelp.lua does the work:
    • opts() describes a mapping and files it under a section.
    • sections() reads the live mappings.
    • open() draws the window.
    • hint() and place_hint() draw the header hints.
  • Each view passes only its title, its section order, and its own notes.

Tests

tests/specs/27_keyhelp.lua covers:

  • Grouping, key collapsing, and how <Space> and < display.
  • That help reflects live mapping changes.
  • The contents of the diff, panel, and merge help windows.
  • The header, panel, and commit-label hints.
  • Remapped review hints.
  • help_key = false.

It also fails if any mapping in a diff, panel, or merge buffer has no description, so a new key can't silently go missing from g?.

The full suite passes (nvim --headless -u tests/run.lua).

Every DiffBandit mapping now carries a "DiffBandit: ..." description and a
help section (util/keyhelp), so :map, which-key, and keymap pickers explain
them. g? (navigation.help_key) opens a floating list of the current
window's keys, read from its live mappings so remaps and disabled keys
show as they are. It is grouped by purpose and explains the compact diff
header and the panel's staged symbols.

Headers show a "g? help" hint (diff, merge, folder diff, commit panel, git
log), the commit message label shows ":w commit" and the amend key, and the
read-only review hint line is built from the configured keys instead of a
hardcoded string.

Fixes #21
Base automatically changed from close-and-reuse-tabs to main November 5, 2026 01:26
@CoreyKaylor
CoreyKaylor merged commit 1acb4a5 into main Nov 5, 2026
1 of 2 checks passed
@CoreyKaylor
CoreyKaylor deleted the keymap-help branch November 5, 2026 01:36
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.

Show the current bindings in the DiffViewer

1 participant