hop.nvim
hop.nvim copied to clipboard
HopLine in operator pending mode not working on lines as a whole
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?
It's not possible right now.
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.
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.
#98 is related
I think #99 is a more elegant and compatible fix for this