What is fuzzy matching?

39 views
Skip to first unread message

Tony Mechelynck

unread,
Apr 29, 2021, 6:07:37 AM4/29/21
to Yegappan Lakhsmanan, Bram Moolenaar, vim_use
The help for :vimgrep (in quickfix.txt with "Last change: 2021 Feb
05", maybe that date is in error) now mentions an [f] flag without
saying what it does. One recent vim_dev thread makes me think that
with the 'f' flag "fuzzy matching" is used. So I used :helpgrep
\<fuzzy\> and found several mentions of fuzzy matching, but AFAICT
they all assume that the reader knows what fuzzy matching is. Nowhere
did I see the expression defined. So what is fuzzy matching?

Best regards,
Tony.

rwmit...@gmail.com

unread,
Apr 29, 2021, 6:23:35 AM4/29/21
to vim_use
In other places, it means a non-exact match is found, allowing for misspellings or transposed letters.

What it means in this specific instance, ie: how fuzzy, how different from the original, I do not know - which is probably what you wanted to know.

Bram Moolenaar

unread,
Apr 29, 2021, 8:26:17 AM4/29/21
to vim...@googlegroups.com, Tony Mechelynck, Yegappan Lakhsmanan, Bram Moolenaar
It appears a part of the patch didn't end up in the git commit:

When the 'f' flag is specified, fuzzy string matching
is used to find matching lines. In this case,
{pattern} is treated as a literal string instead of a
regular expression. See |matchfuzzy()| for more info
about fuzzy matching.


--
hundred-and-one symptoms of being an internet addict:
194. Your business cards contain your e-mail and home page address.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Tony Mechelynck

unread,
Apr 29, 2021, 11:14:30 AM4/29/21
to Bram Moolenaar, vim_use, Yegappan Lakhsmanan
On Thu, Apr 29, 2021 at 2:26 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Tony wrote:
>
> > The help for :vimgrep (in quickfix.txt with "Last change: 2021 Feb
> > 05", maybe that date is in error) now mentions an [f] flag without
> > saying what it does. One recent vim_dev thread makes me think that
> > with the 'f' flag "fuzzy matching" is used. So I used :helpgrep
> > \<fuzzy\> and found several mentions of fuzzy matching, but AFAICT
> > they all assume that the reader knows what fuzzy matching is. Nowhere
> > did I see the expression defined. So what is fuzzy matching?
>
> It appears a part of the patch didn't end up in the git commit:
>
> When the 'f' flag is specified, fuzzy string matching
> is used to find matching lines. In this case,
> {pattern} is treated as a literal string instead of a
> regular expression. See |matchfuzzy()| for more info
> about fuzzy matching.
>

Hm, even |matchfuzzy()| is not very enlightening, but I suppose it
isn't obvious to give aCartesian definition of something fuzzy. I'll
have to go with the set of examples above |matchfuzzypos()| and with
what rwmitchell said above.

Best regards,
Tony.

Yegappan Lakshmanan

unread,
Apr 29, 2021, 11:10:43 PM4/29/21
to Tony Mechelynck, Bram Moolenaar, vim_use
Hi Tony,
We should add a description for "fuzzy matching" to the Vim help.
I will send out a PR.

Fuzzy matching refers to matching strings using non-exact matches.
For example, when you search for the 'get pat' string using fuzzy
matching, it will match the strings 'GetPattern', 'PatternGet',
'getPattern', 'patGetter', 'getSomePattern', 'MatchpatternGet' etc.

:echo matchfuzzy(['GetPattern', 'PatternGet', 'getPattern',
'patGetter', 'getSomePattern', 'MatchpatternGet'], 'get pat')
['patGetter', 'GetPattern', 'PatternGet', 'getPattern',
'getSomePattern', 'MatchpatternGet']

Fuzzy matching will match a string, if all the characters in the search
string are present in the string in the same order. Case is ignored during
the search. Other characters can be present between two characters
in the search string. If the search string has multiple words, then each word
is matched separately. So the words in the search string can be present in
any order in a string.

Fuzzy matching assigns a score for each match based on some criteria.
The match with the highest score is returned first.

Regards,
Yegappan

Tony Mechelynck

unread,
Apr 30, 2021, 1:55:55 AM4/30/21
to Yegappan Lakshmanan, Bram Moolenaar, vim_use
Ah I see. So IIUC Vim's fuzzy matching will match (caselessly) if
there is an extra letter but not if there is a missing letter, and it
won't match swapped letters: if the search string is 'word', then Vim
will find 'WoRd' or 'worrd' but not 'wrd' or 'wrod'. Thanks for
explaining.

Best regards,
Tony.

BPJ

unread,
Apr 30, 2021, 5:15:11 AM4/30/21
to vim_use
IOW fuzzy 'word' is equivalent to regex 'w.*o.*r.*d.*' or '.*w.*o.*r.*d.*'?

/bpj



Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXsGfxY7L1diJ3NZnnV9DyBFh4kg0jGsrcATYJG9VJVXnw%40mail.gmail.com.

Yegappan Lakshmanan

unread,
Apr 30, 2021, 11:15:40 AM4/30/21
to vim_use
Hi,
When fuzzy matching a string, the case is ignored. So a fuzzy 'word' is
sort of equivalent to '\c.*w.*o.*r.*d.*', But when multiple matches are
sorted by the fuzzy match score, the match is much more than a regular
expression match. For example, the score is higher for a match with
less distance between the characters. Similarly matches at the beginning
of a word or after a camel case or underscore are given a higher
score.

- Yegappan
Reply all
Reply to author
Forward
0 new messages