t9md / atom-lazy-motion

Rapid cursor positioning with fuzzy search.
https://atom.io/packages/lazy-motion
MIT License
20 stars 3 forks source link

failed to find literal match #3

Closed jacekkopecky closed 9 years ago

jacekkopecky commented 9 years ago

I'm editing a file that has the text "the c keybinding" in it; using lazy motion and searching for the c doesn't find that. That's with lazy-motion 0.1.9

nylki commented 9 years ago

I can confirm that any exact string containing spaces is not found/highlighted.

t9md commented 9 years ago

Yes, Its expected behavior. Since default lazy-motion.wordRegExp config not include space character. The chars not included this setting is treated as word separator.

This is how it works.

  1. Start lazy-motion
  2. Gather candidate on your first input, all buffer's text is tokenized with wordRegExp.
  3. Candidates are filtered by your input with fuzzaldrin's fuzzy match.

You can modify wordRegExp to include space. But the more we add the character, the more each word become longer and lost uniqueness of each word.

So I don't recommend adding space char to it. If you need search space including char use my isearch package or default search.

You can check currently recognized token by input one space. Since in fuzzaldrin's fuzzy filter match space to any candidates.

As you can see, not only space, ; and ' is also excluded from candidate word since its not included wordRegExp.

image

t9md commented 9 years ago

One note, why single space match all the candidates is fuzzaldrin replace it to blank char.

So, for space in your search chars have no meaning, it been replaced to ''(blank).

But anyway you need to add `(space char) tolazy-motion.wordRegExp` first to make space containing word as candidate.

jacekkopecky commented 9 years ago

Oh, I understand now, that makes perfect sense. My regexp is now [@\w-.():?]+|"[^"\n]*"|'[^'\n]*' to also match string literals.

t9md commented 9 years ago

Default wordRegExp is very depending on my preference for coding CoffeeScript. And not necessarily appropriate for everyone. I think I need to improve default wordRegExp setting. But the more you add chars to this setting, the more you have less candidate and each word got long. This result in you can't reach specific position with lazy search.

jacekkopecky commented 9 years ago

Yup, I like how the regexp is configurable, and it's good to see the trade-offs. I guess initially I didn't quite understand that lazy-jump is focused on tokens rather than other forms of fuzzy matches in the file - it may be because I don't know fuzzaldrin.

t9md commented 9 years ago

Note for future reference for everyone.

If you want to improve or change RegExp setting. Change lazy-motion.wordRegExp and observe how each candidate(or token) would be, by input single space as search char.

Why this single space is special is because fuzzaldrin replace single space to blank char before filtering. And filtering candidates with blank char result in all candidate is matched(no filter happen). Like this way you can observe how your wordRegExp setting change candidates.

This is not intended behavior but its harmless and usefull for check your wordRegExp setting. So until fuzzaldrin change this space replacement behavior, this tips is available.

e.g.

wordRegExp = \w

single numerical and alphabet and underscore char.

image

wordRegExp = \w+

sequence of \w

image