hop.nvim
hop.nvim copied to clipboard
^ anchor does not work
require('hop').hint_patterns({}, '\\v^.')
This should match the first character in every line, instead it matches every character in the window. Interestingly, the corresponding \\v.$ does work.
(NOTE: I know about HopLine, I'm trying to use the above pattern as one part of a longer regex).
I think this is because hint_patterns() uses jump_target.regex_by_case_searching() which sets oneshot = false. I'm not an expert in the codebase but this sounds like the pattern search will be repeated on the remainder of the string that wasn't matched. If there is a string remaining, there will always be a beginning so effectively all characters will be matched. For the $ example, there is no remaining string after the end of a string so this search works correctly.
The simplest, hackiest approach might be to scan the pattern for a ^ at the beginning. If this is found, then oneshot can be set to true, otherwise false.
Yep, that doesn’t work. I’m not sure exactly why. oneshot is to be used for matcher that will match only once per-line, so even if you find ^ only once, repeating the regex for the rest of the line with oneshot = false will just be a waste of resource; it should still return the right answer.
It definitely seems to be matching ^ with the end of the previous match. I was hoping I could use negative lookbehind as a workaround, by replacing all ^ with .@<! (assuming \v), but the same issue happens.