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

Toggle stage hunk

Open axieax opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

When I accidentally stage the hunk my cursor is under, it's frustrating that I can't use the same keybind / command to toggle the staged status of the hunk. I know that undo_stage exists, but it's on a separate keybind, and I couldn't find a way to make a custom mapping which performs one of the actions based on whether the current hunk is staged or not.

Describe the solution you'd like A clear and concise description of what you want to happen.

A hunk_toggle_staged action which stages the hunk under the cursor if unstaged, and vice versa.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Registering a custom command; using the cmdline to find out whether the current line is staged.

Additional context Add any other context or screenshots about the feature request here.

axieax avatar May 01 '23 10:05 axieax

Great idea! I would change it a bit to a line_toggle_staged, not whole hunk

ivan-volnov avatar Oct 04 '23 12:10 ivan-volnov

It's gonna be tricky to implement. Git doesn't keep track of hunks staged. It's a pile fo staged hunks for a given file only.

hinell avatar Oct 05 '23 22:10 hinell

Gitsigns can already track staged hunks if you set _signs_staged_enable = true in setup(). It works by running an extra diff against HEAD and subtracting the hunks.

lewis6991 avatar Oct 06 '23 07:10 lewis6991

@lewis6991 Is there any particular reason for this option to not be documented?

leiteg avatar Apr 11 '24 23:04 leiteg

Because it isn't finished.

lewis6991 avatar Apr 11 '24 23:04 lewis6991

Fair enough!

leiteg avatar Apr 11 '24 23:04 leiteg

Done in #1039

lewis6991 avatar Jun 13 '24 14:06 lewis6991