1
0
forked from aniani/vim

patch 8.2.2813: cannot grep using fuzzy matching

Problem:    Cannot grep using fuzzy matching.
Solution:   Add the "f" flag to :vimgrep. (Yegappan Lakshmanan, closes #8152)
This commit is contained in:
Yegappan Lakshmanan
2021-04-26 21:17:52 +02:00
committed by Bram Moolenaar
parent 5930ddcd25
commit bb01a1ef3a
8 changed files with 160 additions and 62 deletions

View File

@@ -32,7 +32,7 @@ func s:setup_commands(cchar)
command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args>
command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
command! -nargs=* Xexpr <mods>cexpr <args>
command! -count -nargs=* Xvimgrep <mods> <count>vimgrep <args>
command! -count=999 -nargs=* Xvimgrep <mods> <count>vimgrep <args>
command! -nargs=* Xvimgrepadd <mods> vimgrepadd <args>
command! -nargs=* Xgrep <mods> grep <args>
command! -nargs=* Xgrepadd <mods> grepadd <args>
@@ -69,7 +69,7 @@ func s:setup_commands(cchar)
command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args>
command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
command! -nargs=* Xexpr <mods>lexpr <args>
command! -count -nargs=* Xvimgrep <mods> <count>lvimgrep <args>
command! -count=999 -nargs=* Xvimgrep <mods> <count>lvimgrep <args>
command! -nargs=* Xvimgrepadd <mods> lvimgrepadd <args>
command! -nargs=* Xgrep <mods> lgrep <args>
command! -nargs=* Xgrepadd <mods> lgrepadd <args>
@@ -5372,4 +5372,50 @@ func Test_vimgrep_noswapfile()
set swapfile
endfunc
" Test for the :vimgrep 'f' flag (fuzzy match)
func Xvimgrep_fuzzy_match(cchar)
call s:setup_commands(a:cchar)
Xvimgrep /three one/f Xfile*
let l = g:Xgetlist()
call assert_equal(2, len(l))
call assert_equal(['Xfile1', 1, 9, 'one two three'],
\ [bufname(l[0].bufnr), l[0].lnum, l[0].col, l[0].text])
call assert_equal(['Xfile2', 2, 1, 'three one two'],
\ [bufname(l[1].bufnr), l[1].lnum, l[1].col, l[1].text])
Xvimgrep /the/f Xfile*
let l = g:Xgetlist()
call assert_equal(3, len(l))
call assert_equal(['Xfile1', 1, 9, 'one two three'],
\ [bufname(l[0].bufnr), l[0].lnum, l[0].col, l[0].text])
call assert_equal(['Xfile2', 2, 1, 'three one two'],
\ [bufname(l[1].bufnr), l[1].lnum, l[1].col, l[1].text])
call assert_equal(['Xfile2', 4, 4, 'aaathreeaaa'],
\ [bufname(l[2].bufnr), l[2].lnum, l[2].col, l[2].text])
Xvimgrep /aaa/fg Xfile*
let l = g:Xgetlist()
call assert_equal(4, len(l))
call assert_equal(['Xfile1', 2, 1, 'aaaaaa'],
\ [bufname(l[0].bufnr), l[0].lnum, l[0].col, l[0].text])
call assert_equal(['Xfile1', 2, 4, 'aaaaaa'],
\ [bufname(l[1].bufnr), l[1].lnum, l[1].col, l[1].text])
call assert_equal(['Xfile2', 4, 1, 'aaathreeaaa'],
\ [bufname(l[2].bufnr), l[2].lnum, l[2].col, l[2].text])
call assert_equal(['Xfile2', 4, 9, 'aaathreeaaa'],
\ [bufname(l[3].bufnr), l[3].lnum, l[3].col, l[3].text])
call assert_fails('Xvimgrep /xyz/fg Xfile*', 'E480:')
endfunc
func Test_vimgrep_fuzzy_match()
call writefile(['one two three', 'aaaaaa'], 'Xfile1')
call writefile(['one', 'three one two', 'two', 'aaathreeaaa'], 'Xfile2')
call Xvimgrep_fuzzy_match('c')
call Xvimgrep_fuzzy_match('l')
call delete('Xfile1')
call delete('Xfile2')
endfunc
" vim: shiftwidth=2 sts=2 expandtab