Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial hunk staging as operator #421

Open
pedro757 opened this issue Dec 4, 2021 · 13 comments
Open

Partial hunk staging as operator #421

pedro757 opened this issue Dec 4, 2021 · 13 comments
Labels
enhancement New feature or request

Comments

@pedro757
Copy link

pedro757 commented Dec 4, 2021

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 pedro757 added the enhancement New feature or request label Dec 4, 2021
@molleweide
Copy link

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

@pedro757
Copy link
Author

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

@molleweide
Copy link

Haha yeah I think it could be quite interesting feature

@molleweide
Copy link

Very nice when hunks too big

@tsyroid
Copy link

tsyroid commented Mar 13, 2022

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

@j-xella
Copy link

j-xella commented Jul 16, 2022

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?

@afonsocarlos
Copy link

+1

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

@lewis6991
Copy link
Owner

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
Copy link
Owner

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.

@afonsocarlos
Copy link

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

@lewis6991
Copy link
Owner

Fwiw fugitive allows you to do that too.

@xuyangy
Copy link

xuyangy commented Sep 14, 2023

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

@rtalexk
Copy link

rtalexk commented Apr 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants