Skip to content

select_hunk not working as expected on visual modes #1133

@gabrielrov

Description

@gabrielrov

Description

Buggy behavior when using gitsigns.select_hunk or <cmd>Gitsigns select_hunk<CR>.
If used in visual or visual block mode, instead of selecting the whole hunk, it only selects
until the end of it. For visual line, the cursor will jump to the end of hunk without selecting
anything.

I've also noticed that :Gitsigns select_hunk<CR> works fine, but i tend to avoid using keymaps
starting with :, as it can cause little annoyances on my particular config. It's just not as consistent.

Neovim version

v0.11.0

Operating system and version

Ubuntu 24.04.1

Expected behavior

For all visual modes:
Screenshot_20241009_210839

Actual behavior

Visual and visual block:
Screenshot_20241009_211220

Visual line:
Screenshot_20241009_211250

Minimal config

local gitsigns = require('gitsigns')

vim.keymap.set({ 'o', 'x' }, 'ih', gitsigns.select_hunk, { desc = 'Select hunk' })

Steps to reproduce

  1. mkdir gitsigns_issue
  2. cd gitsigns_issue
  3. git init
  4. touch file
  5. git add file
  6. git commit -m 'initial commit'
  7. nvim file
  8. Add some new lines
  9. Go to any new line on the hunk after the first one
  10. Type vih, Vih or <C-v>ih

Gitsigns debug messages

No response

Gitsigns cache

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions