@@ -3537,11 +3537,41 @@ get_next_filename_completion(void)
35373537 int in_fuzzy = ((get_cot_flags () & COT_FUZZY ) != 0 && leader_len > 0 );
35383538 char_u * * sorted_matches ;
35393539 int * fuzzy_indices_data ;
3540+ char_u * last_sep = NULL ;
3541+ size_t path_with_wildcard_len ;
3542+ char_u * path_with_wildcard ;
35403543
35413544 if (in_fuzzy )
35423545 {
3543- vim_free (compl_pattern );
3544- compl_pattern = vim_strsave ((char_u * )"*" );
3546+ last_sep = vim_strrchr (leader , PATHSEP );
3547+ if (last_sep == NULL )
3548+ {
3549+ // No path separator or separator is the last character,
3550+ // fuzzy match the whole leader
3551+ vim_free (compl_pattern );
3552+ compl_pattern = vim_strsave ((char_u * )"*" );
3553+ compl_patternlen = STRLEN (compl_pattern );
3554+ }
3555+ else if (* (last_sep + 1 ) == '\0' )
3556+ in_fuzzy = FALSE;
3557+ else
3558+ {
3559+ // Split leader into path and file parts
3560+ int path_len = last_sep - leader + 1 ;
3561+ path_with_wildcard_len = path_len + 2 ;
3562+ path_with_wildcard = alloc (path_with_wildcard_len );
3563+ if (path_with_wildcard != NULL )
3564+ {
3565+ vim_strncpy (path_with_wildcard , leader , path_len );
3566+ vim_strcat (path_with_wildcard , (char_u * )"*" , path_with_wildcard_len );
3567+ vim_free (compl_pattern );
3568+ compl_pattern = path_with_wildcard ;
3569+ compl_patternlen = STRLEN (compl_pattern );
3570+
3571+ // Move leader to the file part
3572+ leader = last_sep + 1 ;
3573+ }
3574+ }
35453575 }
35463576
35473577 if (expand_wildcards (1 , & compl_pattern , & num_matches , & matches ,
0 commit comments