gitsigns.nvim icon indicating copy to clipboard operation
gitsigns.nvim copied to clipboard

Partial hunk staging as operator

Open pedro757 opened this issue 2 years ago • 13 comments

It would be cool take advantage of the partial hunk staging feature just implemented making a operator to work with motions like:

<leader>hs3j --> stage next 3 lines <leader>hsip --> stage paragraph <leader>hsiw --> stage word and so on..

pedro757 avatar Dec 04 '21 22:12 pedro757

Wonderful! I was just about to ask if this was possible to do!

molleweide avatar Dec 31 '21 11:12 molleweide

It will be a very unique feature, I've never seen it in other Editors. @molleweide

pedro757 avatar Dec 31 '21 12:12 pedro757

Haha yeah I think it could be quite interesting feature

molleweide avatar Dec 31 '21 12:12 molleweide

Very nice when hunks too big

molleweide avatar Dec 31 '21 12:12 molleweide

All in. Was just searching the thread in advance of posting the following issue: In gitgutter I could work with partial hunks (from the documentation):

To stage part of any hunk:

preview the hunk, e.g. <Leader>hp;
move to the preview window, e.g. :wincmd P;
delete the lines you do not want to stage;
stage the remaining lines: either write (:w) the window or stage via <Leader>hs or :GitGutterStageHunk.

Really, really would be wonderful if gitsigns would allow me to do the same. /tms

tsyroid avatar Mar 13 '22 19:03 tsyroid

All in. Was just searching the thread in advance of posting the following issue: In gitgutter I could work with partial hunks (from the documentation):

To stage part of any hunk:

preview the hunk, e.g. <Leader>hp;
move to the preview window, e.g. :wincmd P;
delete the lines you do not want to stage;
stage the remaining lines: either write (:w) the window or stage via <Leader>hs or :GitGutterStageHunk.

Really, really would be wonderful if gitsigns would allow me to do the same. /tms

Agree, wanted to ask about it as well. But this should probably be moved to a seprarate issue, no?

j-xella avatar Jul 16 '22 19:07 j-xella

+1

That's actually the only thing that's missing from vmi-gitgutter for this plugin to be 10/10

afonsocarlos avatar Oct 18 '22 13:10 afonsocarlos

How does vim-gitgutter implement this, last time I checked it doesn't have true partial hunk staging like Gitsigns does, so an operator mapping doesn't make sense.

lewis6991 avatar Oct 18 '22 14:10 lewis6991

btw, not sure if anyone knows this, but if you edit a buffer created by :Gitsigns diffthis you can save/write it to stage changes. This is opposed to vim-gitgutter that allows you to edit the hunk preview window.

lewis6991 avatar Oct 18 '22 14:10 lewis6991

btw, not sure if anyone knows this, but if you edit a buffer created by :Gitsigns diffthis you can save/write it to stage changes. This is opposed to vim-gitgutter that allows you to edit the hunk preview window.

This is exactly what I, and probably most other users, were looking for. I thought the quick preview window edit very handy, but already having the option to edit hunk before staging is already a game changer for me! Also, I might've missed it, but I think it would be great to have this feature documented in README

afonsocarlos avatar Oct 18 '22 14:10 afonsocarlos

Fwiw fugitive allows you to do that too.

lewis6991 avatar Oct 18 '22 14:10 lewis6991

Visual select the changed lines that you want to stage and run Gitsigns stage_hunk (equivalently :'<,'>Gitsings stage_hunk).

xuyangy avatar Sep 14 '23 17:09 xuyangy

I have the following mapping on my config

map({ 'n', 'v' }, '<leader>ghs', ':Gitsigns stage_hunk<CR>', 'Stage hunk')

This allow my to select lines (V) then stage selected lines, i.e: V3j<Space>ghs translates to Select the current line, move 3 lines below (4 lines selected) and stage them.

rtalexk avatar Apr 10 '24 00:04 rtalexk