How do I jump between git diff hunks in the current buffer and stage or preview them with gitsigns.nvim?
Answer
]c / [c (gitsigns.nvim)
Explanation
gitsigns.nvim decorates your buffer with inline git change indicators and provides motions to jump directly between diff hunks without opening a separate diff view. Combined with hunk staging and preview actions, you can review and stage individual changes without ever leaving the file you are working in.
How it works
After installing gitsigns.nvim and setting up the recommended keymaps, the following motions and actions are available:
Navigation:
]c— jump to the next hunk (added, changed, or deleted lines)[c— jump to the previous hunk
Hunk actions (example mappings from the README):
<leader>hs— stage the hunk under the cursor<leader>hr— reset (undo) the hunk<leader>hp— preview the hunk in a floating window<leader>hb— showgit blamefor the current line inline
The ]c / [c motions accept a count: 3]c jumps forward three hunks.
Example
You have modified several functions in a large file. Press ]c to jump to the first changed hunk. Use <leader>hp to preview the diff in context. If the change looks good, press <leader>hs to stage just that hunk. Continue with ]c to move to the next hunk.
Tips
]cand[care the gitsigns-provided versions; the vanilla Vim]c/[conly work in:diffmode. gitsigns overrides them whenvim.wo.diffis false- Use
<leader>hSto stage the entire buffer at once <leader>tbtoggles current-line blame (inline virtual text showing author/date)- Run
:Gitsigns toggle_signsto show or hide the sign column decorations