# HG changeset patch # User Bram Moolenaar # Date 1603629006 -3600 # Node ID ba3f547dc4907a9d39f20954e663c71c2219958b # Parent 8fef39a36cb9d55e6a611b75e0cbcd0aa0e8b16b patch 8.2.1901: variable completion does not work in command line window Commit: https://github.com/vim/vim/commit/4ff2f2fb6bef01a06bd726bae8dfa8dd6355d594 Author: Bram Moolenaar Date: Sun Oct 25 13:22:42 2020 +0100 patch 8.2.1901: variable completion does not work in command line window Problem: Variable completion does not work in command line window. Solution: Use the "prevwin". (closes https://github.com/vim/vim/issues/7198) diff --git a/src/evalvars.c b/src/evalvars.c --- a/src/evalvars.c +++ b/src/evalvars.c @@ -1981,7 +1981,13 @@ get_user_var_name(expand_T *xp, int idx) } // b: variables - ht = &curbuf->b_vars->dv_hashtab; + ht = +#ifdef FEAT_CMDWIN + // In cmdwin, the alternative buffer should be used. + (cmdwin_type != 0 && get_cmdline_type() == NUL) ? + &prevwin->w_buffer->b_vars->dv_hashtab : +#endif + &curbuf->b_vars->dv_hashtab; if (bdone < ht->ht_used) { if (bdone++ == 0) @@ -1994,7 +2000,13 @@ get_user_var_name(expand_T *xp, int idx) } // w: variables - ht = &curwin->w_vars->dv_hashtab; + ht = +#ifdef FEAT_CMDWIN + // In cmdwin, the alternative window should be used. + (cmdwin_type != 0 && get_cmdline_type() == NUL) ? + &prevwin->w_vars->dv_hashtab : +#endif + &curwin->w_vars->dv_hashtab; if (wdone < ht->ht_used) { if (wdone++ == 0) diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -346,7 +346,10 @@ func Test_compl_in_cmdwin() set wildmenu wildchar= com! -nargs=1 -complete=command GetInput let input = com! -buffer TestCommand echo 'TestCommand' + let w:test_winvar = 'winvar' + let b:test_bufvar = 'bufvar' + " User-defined commands let input = '' call feedkeys("q:iGetInput T\\\", 'tx!') call assert_equal('TestCommand', input) @@ -355,8 +358,30 @@ func Test_compl_in_cmdwin() call feedkeys("q::GetInput T\\:q\", 'tx!') call assert_equal('T', input) + + com! -nargs=1 -complete=var GetInput let input = + " Window-local variables + let input = '' + call feedkeys("q:iGetInput w:test_\\\", 'tx!') + call assert_equal('w:test_winvar', input) + + let input = '' + call feedkeys("q::GetInput w:test_\\:q\", 'tx!') + call assert_equal('w:test_', input) + + " Buffer-local variables + let input = '' + call feedkeys("q:iGetInput b:test_\\\", 'tx!') + call assert_equal('b:test_bufvar', input) + + let input = '' + call feedkeys("q::GetInput b:test_\\:q\", 'tx!') + call assert_equal('b:test_', input) + delcom TestCommand delcom GetInput + unlet w:test_winvar + unlet b:test_bufvar set wildmenu& wildchar& endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1901, +/**/ 1900, /**/ 1899,