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

^ anchor does not work

Open smackesey opened this issue 4 years ago • 3 comments

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).

smackesey avatar Sep 09 '21 17:09 smackesey

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.

shyun3 avatar Nov 18 '21 00:11 shyun3

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.

hadronized avatar Jun 21 '22 10:06 hadronized

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.

Zantier avatar Dec 11 '22 23:12 Zantier