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

HopLine in operator pending mode not working on lines as a whole

Open IngoMeyer441 opened this issue 1 year ago • 5 comments

Thanks for maintaining this nice plugin. I was trying to configure a key binding for operator pending mode which deletes several lines at once. For this a tried to add this configuration:

vim.keymap.set('', '<Space>j', function()
  hop.hint_lines({ direction = directions.AFTER_CURSOR, current_line_only = false })
end, {remap=true})

It works great to jump to a line in normal mode, but operator mode behaves a bit odd. In this example text (cursor position marked with |)

ab|c
def
ghi

I would expect to delete all lines when jumping to the last line with d<Space>j. Instead, the text

abhi

is left in the buffer. Is it somehow possible to tell hop to work on whole lines?

IngoMeyer441 avatar Feb 21 '24 15:02 IngoMeyer441

It's not possible right now.

smoka7 avatar Feb 21 '24 17:02 smoka7

The problem is even more general than that (unless I'm missing something which is very possible). hint_words for example behaves just like vim's w and b in normal mode, but in operator pending mode the AFTER_CURSOR version deletes the character with the hint too, unlike what vim does for the equivalent (dw). But then BEFORE_CURSOR works exactly like db.

Since it's different behavior depending on whether you are just navigating or in the middle of an operation, the hint_offset option is not relevant here. It would make things work correctly for operations but break it for normal navigation.

rosshadden avatar Apr 23 '24 19:04 rosshadden

This issue in the original repo might be relevant: https://github.com/hadronized/hop.nvim/issues/127

vim does allow forced motions so one workaround I've used for this problem is to map something like:

vim.keymap.set('o', '<Space>j', 'V:lua my_hint_lines()<CR>')

where V is used to force linewise motion and the Lua function was defined separately as my_hint_lines.

One issue I've found though is that when you do something like d<Space>j and then cancel the hints by hitting escape, it still deletes the current line where the cursor is pointing. Not sure how to prevent that at the moment.

shyun3 avatar May 31 '24 15:05 shyun3

#98 is related

myarcana avatar Dec 22 '24 23:12 myarcana

I think #99 is a more elegant and compatible fix for this

myarcana avatar Dec 23 '24 00:12 myarcana