hop.nvim
hop.nvim copied to clipboard
In the nightly of neovim I've started getting "-> there's no such thing we can see" for "special characters"
The following mapping works differently in neovim 0.6 and the latest master version.
vim.api.nvim_set_keymap('n', 'f', "<cmd>lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.AFTER_CURSOR, current_line_only = true })<cr>", {})
What happens is that when I press f( and in 0.6, it will correctly find all ( and highlights them. But in the latest version it just says "-> there's no such thing we can see" error message.
I'm not sure if this is a problem in hop.nvim or neovim though. But in the README it says users of nightly versions should use the latest nightly so I would expect it to work.
I tried to debug this issue and this is what I found. The problem seems to be in vim.fn.getchar. I've added a print statement in hop_char1:
function M.hint_char1(opts)
opts = get_command_opts(opts)
local cur_ns = vim.api.nvim_create_namespace('hop_grey_cur')
add_virt_cur(cur_ns)
vim.cmd('redraw')
local ok, c = pcall(vim.fn.getchar)
if not ok then
clear_namespace(0, cur_ns)
return
end
print('hint_char1 - 1: _', c, '_', vim.fn.nr2char(c), '_')
hint_with(hint.by_case_searching(vim.fn.nr2char(c), true, opts), opts)
end
and here's the result (top one is new Neovim 0.7, bottom one is Neovim 0.6):

According to the docs:
Without [expr] and when [expr] is 0 a whole character or special key is returned. If it is a single character, the result is a number. Use nr2char() to convert it to a String. Otherwise a String is returned with the encoded character. For a special key it's a String with a sequence of bytes starting with 0x80 (decimal: 128). This is the same value as the String "<Key>", e.g., "<Left>". The returned value is also a String when a modifier (shift, control, alt) was used that is not included in the character.
When [expr] is 0 and Esc is typed, there will be a short delay while Vim waits to see if this is the start of an escape sequence.
When [expr] is 1 only the first byte is returned. For a one-byte character it is the character itself as a number. Use nr2char() to convert it to a String.
So it looks like, in case of hop.nvim, we do not pass any argument to getchar so it can actually return a string in some cases but it looks like the code below this function always expects a number.
Here's my temporary hot-fix, it seems to work on Neovim 0.7: https://github.com/synaptiko/hop.nvim/commit/36450e8d30f33245d14ced254e003f04cb981ba1