@@ -5912,6 +5912,7 @@ vgr_match_buflines(
59125912 qf_list_T * qfl ,
59135913 char_u * fname ,
59145914 buf_T * buf ,
5915+ char_u * spat ,
59155916 regmmatch_T * regmatch ,
59165917 long * tomatch ,
59175918 int duplicate_name ,
@@ -5920,45 +5921,91 @@ vgr_match_buflines(
59205921 int found_match = FALSE;
59215922 long lnum ;
59225923 colnr_T col ;
5924+ int pat_len = STRLEN (spat );
59235925
59245926 for (lnum = 1 ; lnum <= buf -> b_ml .ml_line_count && * tomatch > 0 ; ++ lnum )
59255927 {
59265928 col = 0 ;
5927- while (vim_regexec_multi (regmatch , curwin , buf , lnum ,
5928- col , NULL , NULL ) > 0 )
5929+ if (!(flags & VGR_FUZZY ))
59295930 {
5930- // Pass the buffer number so that it gets used even for a
5931- // dummy buffer, unless duplicate_name is set, then the
5932- // buffer will be wiped out below.
5933- if (qf_add_entry (qfl ,
5934- NULL , // dir
5935- fname ,
5936- NULL ,
5937- duplicate_name ? 0 : buf -> b_fnum ,
5938- ml_get_buf (buf ,
5939- regmatch -> startpos [0 ].lnum + lnum , FALSE),
5940- regmatch -> startpos [0 ].lnum + lnum ,
5941- regmatch -> startpos [0 ].col + 1 ,
5942- FALSE, // vis_col
5943- NULL , // search pattern
5944- 0 , // nr
5945- 0 , // type
5946- TRUE // valid
5947- ) == QF_FAIL )
5931+ // Regular expression match
5932+ while (vim_regexec_multi (regmatch , curwin , buf , lnum ,
5933+ col , NULL , NULL ) > 0 )
59485934 {
5949- got_int = TRUE;
5950- break ;
5935+ // Pass the buffer number so that it gets used even for a
5936+ // dummy buffer, unless duplicate_name is set, then the
5937+ // buffer will be wiped out below.
5938+ if (qf_add_entry (qfl ,
5939+ NULL , // dir
5940+ fname ,
5941+ NULL ,
5942+ duplicate_name ? 0 : buf -> b_fnum ,
5943+ ml_get_buf (buf ,
5944+ regmatch -> startpos [0 ].lnum + lnum , FALSE),
5945+ regmatch -> startpos [0 ].lnum + lnum ,
5946+ regmatch -> startpos [0 ].col + 1 ,
5947+ FALSE, // vis_col
5948+ NULL , // search pattern
5949+ 0 , // nr
5950+ 0 , // type
5951+ TRUE // valid
5952+ ) == QF_FAIL )
5953+ {
5954+ got_int = TRUE;
5955+ break ;
5956+ }
5957+ found_match = TRUE;
5958+ if (-- * tomatch == 0 )
5959+ break ;
5960+ if ((flags & VGR_GLOBAL ) == 0
5961+ || regmatch -> endpos [0 ].lnum > 0 )
5962+ break ;
5963+ col = regmatch -> endpos [0 ].col
5964+ + (col == regmatch -> endpos [0 ].col );
5965+ if (col > (colnr_T )STRLEN (ml_get_buf (buf , lnum , FALSE)))
5966+ break ;
5967+ }
5968+ }
5969+ else
5970+ {
5971+ char_u * str = ml_get_buf (buf , lnum , FALSE);
5972+ int score ;
5973+ int_u matches [MAX_FUZZY_MATCHES ];
5974+ int_u sz = sizeof (matches ) / sizeof (matches [0 ]);
5975+
5976+ // Fuzzy string match
5977+ while (fuzzy_match (str + col , spat , FALSE, & score , matches , sz ) > 0 )
5978+ {
5979+ // Pass the buffer number so that it gets used even for a
5980+ // dummy buffer, unless duplicate_name is set, then the
5981+ // buffer will be wiped out below.
5982+ if (qf_add_entry (qfl ,
5983+ NULL , // dir
5984+ fname ,
5985+ NULL ,
5986+ duplicate_name ? 0 : buf -> b_fnum ,
5987+ str ,
5988+ lnum ,
5989+ matches [0 ] + col + 1 ,
5990+ FALSE, // vis_col
5991+ NULL , // search pattern
5992+ 0 , // nr
5993+ 0 , // type
5994+ TRUE // valid
5995+ ) == QF_FAIL )
5996+ {
5997+ got_int = TRUE;
5998+ break ;
5999+ }
6000+ found_match = TRUE;
6001+ if (-- * tomatch == 0 )
6002+ break ;
6003+ if ((flags & VGR_GLOBAL ) == 0 )
6004+ break ;
6005+ col = matches [pat_len - 1 ] + col + 1 ;
6006+ if (col > (colnr_T )STRLEN (str ))
6007+ break ;
59516008 }
5952- found_match = TRUE;
5953- if (-- * tomatch == 0 )
5954- break ;
5955- if ((flags & VGR_GLOBAL ) == 0
5956- || regmatch -> endpos [0 ].lnum > 0 )
5957- break ;
5958- col = regmatch -> endpos [0 ].col
5959- + (col == regmatch -> endpos [0 ].col );
5960- if (col > (colnr_T )STRLEN (ml_get_buf (buf , lnum , FALSE)))
5961- break ;
59626009 }
59636010 line_breakcheck ();
59646011 if (got_int )
@@ -6163,7 +6210,7 @@ vgr_process_files(
61636210 // Try for a match in all lines of the buffer.
61646211 // For ":1vimgrep" look for first match only.
61656212 found_match = vgr_match_buflines (qf_get_curlist (qi ),
6166- fname , buf , & cmd_args -> regmatch ,
6213+ fname , buf , cmd_args -> spat , & cmd_args -> regmatch ,
61676214 & cmd_args -> tomatch , duplicate_name , cmd_args -> flags );
61686215
61696216 if (using_dummy )
0 commit comments