diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-09-11 22:25:15 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-09-11 22:25:15 +0200 |
commit | 635414dd2f3ae7d4d972d79b806348a6516cb91a (patch) | |
tree | 70ba4988a414e4c1b76eb9f59ace2c3afba39ad3 /runtime | |
parent | c2c820563441499892359da949db3c8f7f16d109 (diff) |
patch 8.2.1665: cannot do fuzzy string matchingv8.2.1665
Problem: Cannot do fuzzy string matching.
Solution: Add matchfuzzy(). (Yegappan Lakshmanan, closes #6932)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 24 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index e72a388302..68884ba1ed 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2641,6 +2641,7 @@ matcharg({nr}) List arguments of |:match| matchdelete({id} [, {win}]) Number delete match identified by {id} matchend({expr}, {pat} [, {start} [, {count}]]) Number position where {pat} ends in {expr} +matchfuzzy({list}, {str}) List fuzzy match {str} in {list} matchlist({expr}, {pat} [, {start} [, {count}]]) List match and submatches of {pat} in {expr} matchstr({expr}, {pat} [, {start} [, {count}]]) @@ -7307,6 +7308,29 @@ matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()* Can also be used as a |method|: > GetText()->matchend('word') + +matchfuzzy({list}, {str}) *matchfuzzy()* + Returns a list with all the strings in {list} that fuzzy + match {str}. The strings in the returned list are sorted + based on the matching score. {str} is treated as a literal + string and regular expression matching is NOT supported. + The maximum supported {str} length is 256. + + If there are no matching strings or there is an error, then an + empty list is returned. If length of {str} is greater than + 256, then returns an empty list. + + Example: > + :echo matchfuzzy(["clay", "crow"], "cay") +< results in ["clay"]. > + :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") +< results in a list of buffer names fuzzy matching "ndl". > + :echo v:oldfiles->matchfuzzy("test") +< results in a list of file names fuzzy matching "test". > + :let l = readfile("buffer.c")->matchfuzzy("str") +< results in a list of lines in "buffer.c" fuzzy matching "str". + + matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()* Same as |match()|, but return a |List|. The first item in the list is the matched string, same as what matchstr() would diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index 1dbfba128b..1e5915f41b 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -603,6 +603,7 @@ String manipulation: *string-functions* charclass() class of a character match() position where a pattern matches in a string matchend() position where a pattern match ends in a string + matchfuzzy() fuzzy matches a string in a list of strings matchstr() match of a pattern in a string matchstrpos() match and positions of a pattern in a string matchlist() like matchstr() and also return submatches |