comparison runtime/doc/eval.txt @ 22355:0491b9cafd44 v8.2.1726

patch 8.2.1726: fuzzy matching only works on strings Commit: https://github.com/vim/vim/commit/4f73b8e9cc83f647b34002554a8bdf9abec0a82f Author: Bram Moolenaar <Bram@vim.org> Date: Tue Sep 22 20:33:50 2020 +0200 patch 8.2.1726: fuzzy matching only works on strings Problem: Fuzzy matching only works on strings. Solution: Support passing a dict. Add matchfuzzypos() to also get the match positions. (Yegappan Lakshmanan, closes #6947)
author Bram Moolenaar <Bram@vim.org>
date Tue, 22 Sep 2020 20:45:04 +0200
parents 75ff30a78189
children 0e231e8e70f8
comparison
equal deleted inserted replaced
22354:19139cc50651 22355:0491b9cafd44
2639 Number highlight positions with {group} 2639 Number highlight positions with {group}
2640 matcharg({nr}) List arguments of |:match| 2640 matcharg({nr}) List arguments of |:match|
2641 matchdelete({id} [, {win}]) Number delete match identified by {id} 2641 matchdelete({id} [, {win}]) Number delete match identified by {id}
2642 matchend({expr}, {pat} [, {start} [, {count}]]) 2642 matchend({expr}, {pat} [, {start} [, {count}]])
2643 Number position where {pat} ends in {expr} 2643 Number position where {pat} ends in {expr}
2644 matchfuzzy({list}, {str}) List fuzzy match {str} in {list} 2644 matchfuzzy({list}, {str} [, {dict}])
2645 List fuzzy match {str} in {list}
2646 matchfuzzypos({list}, {str} [, {dict}])
2647 List fuzzy match {str} in {list}
2645 matchlist({expr}, {pat} [, {start} [, {count}]]) 2648 matchlist({expr}, {pat} [, {start} [, {count}]])
2646 List match and submatches of {pat} in {expr} 2649 List match and submatches of {pat} in {expr}
2647 matchstr({expr}, {pat} [, {start} [, {count}]]) 2650 matchstr({expr}, {pat} [, {start} [, {count}]])
2648 String {count}'th match of {pat} in {expr} 2651 String {count}'th match of {pat} in {expr}
2649 matchstrpos({expr}, {pat} [, {start} [, {count}]]) 2652 matchstrpos({expr}, {pat} [, {start} [, {count}]])
7309 7312
7310 Can also be used as a |method|: > 7313 Can also be used as a |method|: >
7311 GetText()->matchend('word') 7314 GetText()->matchend('word')
7312 7315
7313 7316
7314 matchfuzzy({list}, {str}) *matchfuzzy()* 7317 matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7315 Returns a list with all the strings in {list} that fuzzy 7318 If {list} is a list of strings, then returns a list with all
7316 match {str}. The strings in the returned list are sorted 7319 the strings in {list} that fuzzy match {str}. The strings in
7317 based on the matching score. {str} is treated as a literal 7320 the returned list are sorted based on the matching score.
7318 string and regular expression matching is NOT supported. 7321
7319 The maximum supported {str} length is 256. 7322 If {list} is a list of dictionaries, then the optional {dict}
7323 argument supports the following items:
7324 key key of the item which is fuzzy matched against
7325 {str}. The value of this item should be a
7326 string.
7327 text_cb |Funcref| that will be called for every item
7328 in {list} to get the text for fuzzy matching.
7329 This should accept a dictionary item as the
7330 argument and return the text for that item to
7331 use for fuzzy matching.
7332
7333 {str} is treated as a literal string and regular expression
7334 matching is NOT supported. The maximum supported {str} length
7335 is 256.
7320 7336
7321 If there are no matching strings or there is an error, then an 7337 If there are no matching strings or there is an error, then an
7322 empty list is returned. If length of {str} is greater than 7338 empty list is returned. If length of {str} is greater than
7323 256, then returns an empty list. 7339 256, then returns an empty list.
7324 7340
7325 Example: > 7341 Example: >
7326 :echo matchfuzzy(["clay", "crow"], "cay") 7342 :echo matchfuzzy(["clay", "crow"], "cay")
7327 < results in ["clay"]. > 7343 < results in ["clay"]. >
7328 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") 7344 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7329 < results in a list of buffer names fuzzy matching "ndl". > 7345 < results in a list of buffer names fuzzy matching "ndl". >
7346 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7347 < results in a list of buffer information dicts with buffer
7348 names fuzzy matching "ndl". >
7349 :echo getbufinfo()->matchfuzzy("spl",
7350 \ {'text_cb' : {v -> v.name}})
7351 < results in a list of buffer information dicts with buffer
7352 names fuzzy matching "spl". >
7330 :echo v:oldfiles->matchfuzzy("test") 7353 :echo v:oldfiles->matchfuzzy("test")
7331 < results in a list of file names fuzzy matching "test". > 7354 < results in a list of file names fuzzy matching "test". >
7332 :let l = readfile("buffer.c")->matchfuzzy("str") 7355 :let l = readfile("buffer.c")->matchfuzzy("str")
7333 < results in a list of lines in "buffer.c" fuzzy matching "str". 7356 < results in a list of lines in "buffer.c" fuzzy matching "str".
7334 7357
7358 matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7359 Same as |matchfuzzy()|, but returns the list of matched
7360 strings and the list of character positions where characters
7361 in {str} matches.
7362
7363 If {str} matches multiple times in a string, then only the
7364 positions for the best match is returned.
7365
7366 If there are no matching strings or there is an error, then a
7367 list with two empty list items is returned.
7368
7369 Example: >
7370 :echo matchfuzzypos(['testing'], 'tsg')
7371 < results in [['testing'], [[0, 2, 6]]] >
7372 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7373 < results in [['lacy', 'clay'], [[0, 1], [1, 2]]] >
7374 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7375 < results in [{'id': 10, 'text': 'hello'}] [[2, 3]]
7335 7376
7336 matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()* 7377 matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7337 Same as |match()|, but return a |List|. The first item in the 7378 Same as |match()|, but return a |List|. The first item in the
7338 list is the matched string, same as what matchstr() would 7379 list is the matched string, same as what matchstr() would
7339 return. Following items are submatches, like "\1", "\2", etc. 7380 return. Following items are submatches, like "\1", "\2", etc.