diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 620c66ba9e..8b15870b20 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1586,7 +1586,9 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use in_quote = !in_quote; // An argument can contain just about everything, except // characters that end the command and white space. - } else if (c == '|' || c == '\n' || c == '"' || ascii_iswhite(c)) { + } else if (c == '|' || c == '\n' || c == '"' + || (ascii_iswhite(c) && (!(eap != NULL && (eap->argt & EX_NOSPC)) + || usefilter))) { len = 0; // avoid getting stuck when space is in 'isfname' while (*p != NUL) { c = utf_ptr2char(p); diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index aa9d66a5c3..a2ea0cc1de 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -5321,6 +5321,22 @@ func Test_rulerformat_empty() set rulerformat& endfunc +func Test_cmdline_complete_with_space() + call mkdir('Xspc', 'R') + let save_cwd = getcwd() + cd Xspc + call writefile([], 'foo bar') + call writefile([], 'baz') + call writefile([], 'bz') + + " This should expand to foo\ bar, not add 3 space separated + " files: foo baz bz + call feedkeys(":badd foo b\\\"\", 'xt') + call assert_equal('"badd foo\ bar', @:) + + call chdir(save_cwd) +endfunc + func Test_wildmode_noinsert() command! -nargs=1 -complete=custom,T MyCmd echo func T(a, c, p)