# HG changeset patch # User Bram Moolenaar # Date 1686866403 -7200 # Node ID 0da40da0bbaa5a1758270ea1994baecba963bb80 # Parent 5782057ea5d4b608af2846b75da902d829af60f6 patch 9.0.1636: expanding a pattern interferes with cmdline completion Commit: https://github.com/vim/vim/commit/094dd152fe1d47878ec6c0b3f54b03ffde7f4a2d Author: zeertzjq Date: Thu Jun 15 22:51:57 2023 +0100 patch 9.0.1636: expanding a pattern interferes with cmdline completion Problem: Expanding a pattern interferes with command line completion. Solution: Set the file index only when appropriate. (closes https://github.com/vim/vim/issues/12519) diff --git a/src/cmdexpand.c b/src/cmdexpand.c --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -957,7 +957,7 @@ ExpandOne( int mode) { char_u *ss = NULL; - static int findex; + static int findex; // TODO: Move into expand_T static char_u *orig_save = NULL; // kept value of orig int orig_saved = FALSE; int i; @@ -971,8 +971,9 @@ ExpandOne( if (mode == WILD_CANCEL) ss = vim_strsave(orig_save ? orig_save : (char_u *)""); else if (mode == WILD_APPLY) - ss = vim_strsave(findex == -1 ? (orig_save ? - orig_save : (char_u *)"") : xp->xp_files[findex]); + ss = vim_strsave(findex == -1 + ? (orig_save ? orig_save : (char_u *)"") + : xp->xp_files[findex]); // free old names if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) @@ -985,7 +986,9 @@ ExpandOne( if (compl_match_array != NULL) cmdline_pum_remove(); } - findex = 0; + // TODO: Remove condition if "findex" is part of expand_T ? + if (mode != WILD_EXPAND_FREE && mode != WILD_ALL && mode != WILD_ALL_KEEP) + findex = 0; if (mode == WILD_FREE) // only release file name return NULL; diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -1336,6 +1336,30 @@ func Test_cmdline_complete_various() call assert_equal('"py3file', @:) endfunc +" Test that expanding a pattern doesn't interfere with cmdline completion. +func Test_expand_during_cmdline_completion() + func ExpandStuff() + badd