How do I preview, stage, and navigate Git hunks inline with gitsigns?
Answer
:Gitsigns preview_hunk
Explanation
gitsigns.nvim shows Git diff indicators in the sign column and provides hunk-level operations — preview, stage, reset, and navigate — all without leaving Vim. It's faster than fugitive for quick inline Git operations.
How it works
:Gitsigns preview_hunk— show the hunk diff in a floating window:Gitsigns stage_hunk— stage the current hunk:Gitsigns reset_hunk— discard changes in the current hunk:Gitsigns next_hunk/prev_hunk— navigate between changed sections- Signs appear automatically:
+(added),~(modified),-(deleted)
Example
" Recommended keybindings
nnoremap ]c :Gitsigns next_hunk<CR>
nnoremap [c :Gitsigns prev_hunk<CR>
nnoremap <leader>hp :Gitsigns preview_hunk<CR>
nnoremap <leader>hs :Gitsigns stage_hunk<CR>
nnoremap <leader>hr :Gitsigns reset_hunk<CR>
nnoremap <leader>hb :Gitsigns blame_line<CR>
Sign column shows:
│+ added line
│~ modified line
│- deleted line
<leader>hp shows a floating diff preview
<leader>hs stages just that hunk
Tips
blame_lineshows inline Git blame for the current line- Visual mode: select lines then
:Gitsigns stage_hunkto stage partial hunks :Gitsigns diffthisopens a diff of the current file vs index- Performance: gitsigns is async and handles large repos efficiently