Git keymaps are distributed across multiple plugins, each serving different purposes. This page consolidates all git-related keymaps for easy reference.
Git functionality is split across five plugins:
- Gitsigns - Buffer-level hunk operations
- Snacks - Pickers and browser integration
- Neogit - Full git UI
- CodeDiff - Side-by-side diffs
- Toggleterm - Lazygit and terminal git commands
Gitsigns (hunk operations)
Manage git hunks directly in the current buffer. Keymaps defined in lua/plugins/git.lua:66.
Hunk navigation
| Key | Mode | Description |
|---|
[g | normal | Previous git hunk |
]g | normal | Next git hunk |
Hunk navigation wraps around and targets all hunks (staged and unstaged) using target = "all".
Hunk preview
| Key | Mode | Description |
|---|
<leader>gP | normal | Preview hunk (floating popup) |
<leader>gp | normal | Preview hunk (inline overlay) |
Hunk staging
| Key | Mode | Description |
|---|
<leader>ga | normal | Stage hunk (git add) |
<leader>gu | normal | Unstage hunk |
<leader>gA | normal | Stage entire buffer |
<leader>gu toggles the stage state for the current hunk. This replaces the deprecated undo_stage_hunk() function.
Hunk reset
| Key | Mode | Description |
|---|
<leader>gr | normal | Reset hunk (discard changes) |
<leader>gR | normal | Reset entire buffer (discard all changes) |
Reset operations discard changes permanently. Use preview keymaps first to verify what will be removed.
Blame
| Key | Mode | Description |
|---|
<leader>gb | normal | Blame line (popup with commit info) |
<leader>gB | normal | Blame buffer (full buffer view) |
<leader>GB | normal | Toggle inline blame (virtual text) |
Inline blame shows commit info at the end of each line. The formatter replaces your git username with “You” for clarity. See lua/plugins/git.lua:39.
Diff
| Key | Mode | Description |
|---|
<leader>gD | normal | Diff buffer vs HEAD (vim split) |
Snacks (pickers and browser)
Git pickers and browser integration. Keymaps defined in lua/plugins/snacks.lua:108.
| Key | Mode | Description |
|---|
<leader>gl | normal | Git log for current line |
<leader>gd | normal | Git diff hunks (picker) |
<leader>gS | normal | Git stash browser (picker) |
<leader>go | normal, visual | Open file/selection on GitHub |
<leader>gl shows commits that specifically modified the current line, different from full repo history.
<leader>go opens files in Google Chrome by default. The browser is configured at lua/plugins/snacks.lua:126.
Neogit (main git UI)
Full interactive git interface. Keymaps defined in lua/plugins/git.lua:252.
| Key | Mode | Description |
|---|
<leader>gn | normal | Open Neogit status panel |
<leader>gc | normal | Neogit commit (skip status) |
Neogit provides a full git UI for staging, committing, pushing, pulling, rebasing, stashing, and more. Press ? inside Neogit for all available actions.
Neogit features
Neogit integrates with CodeDiff and Snacks for enhanced functionality:
integrations = {
codediff = true,
snacks = true,
}
diff_viewer = "codediff"
See lua/plugins/git.lua:268.
CodeDiff (side-by-side diffs)
Advanced diff viewer with staging support. Keymaps defined in lua/plugins/git.lua:199.
| Key | Mode | Description |
|---|
<leader>dd | normal | Toggle CodeDiff explorer |
<leader>dh | normal | File history (all files) |
<leader>d. | normal | Current file history |
<leader>df | normal | Current file diff vs HEAD |
<leader>dm | normal | Merge-base diff vs origin/main |
<leader>dM | normal | Merge-base diff vs custom branch |
CodeDiff shows uncommitted changes with side-by-side staging. Press g? inside the view for help and gm to align moved lines.
Merge-base diffs (<leader>dm) show only changes introduced since branching, similar to GitHub PR diffs.
Lazygit (terminal UI)
Alternative terminal-based git UI. Keymaps defined in lua/plugins/toggleterm.lua:217.
| Key | Mode | Description |
|---|
<leader>gg | normal | Lazygit in floating terminal |
<leader>GD | normal | Git diff for current file (with delta) |
Lazygit is an alternative to Neogit with a different workflow. Use whichever you prefer.
Configuration comparison
Gitsigns signs
Preview config
Blame formatter
Gitsigns uses custom signs for different change types:| Type | Sign | Description |
|---|
| add | ┃ | New lines |
| change | ┃ | Modified lines |
| delete | _ | Deleted lines |
| topdelete | ‾ | Deleted at top |
| changedelete | ~ | Changed and deleted |
| untracked | ┆ | Untracked files |
Staged signs use the same icons. See lua/plugins/git.lua:6. Hunk preview windows use rounded borders and cursor positioning:preview_config = {
border = "rounded",
style = "minimal",
relative = "cursor",
row = 0,
col = 1,
}
See lua/plugins/git.lua:57. Inline blame uses a custom formatter to replace your name with “You”:local author = blame_info.author
local git_user = vim.fn.system("git config user.name"):gsub("\n", "")
if author == git_user then
author = "You"
end
See lua/plugins/git.lua:44.
Workflow recommendations
For quick hunk-level changes, use Gitsigns keymaps. For commits and complex operations, use Neogit or Lazygit. For reviewing changes before committing, use CodeDiff.
Common workflows
- Review changes:
<leader>dd (CodeDiff) or <leader>gd (Snacks hunks)
- Stage hunks:
<leader>ga (stage) → <leader>gc (commit)
- Full git UI:
<leader>gn (Neogit) → press ? for help
- Quick commit:
<leader>gA (stage all) → <leader>gc (commit)
- Blame investigation:
<leader>gb (line) → <leader>gl (line history)
Be careful with reset operations (<leader>gr, <leader>gR) as they discard changes without confirmation.