Skip to content

Commit

Permalink
Problem: exists(':keepalt') return 0
Browse files Browse the repository at this point in the history
Problem:  exists(':keepalt') returns 0
Solution: use correct length when finding command,
          also ignore :{ and :} when expanding
          command line items

fixes: vim#15305

Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
chrisbra committed Jul 25, 2024
1 parent dc373d4 commit 9e3734e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4057,7 +4057,7 @@ cmp_cmdmod_info(const void *a, const void *b)
cmdmod_info_T *cm1 = (cmdmod_info_T *)a;
cmdmod_info_T *cm2 = (cmdmod_info_T *)b;

return STRNCMP(cm1->name, cm2->name, cm2->minlen);
return STRNCMP(cm1->name, cm2->name, MAX(cm1->minlen, cm2->minlen));
}

/*
Expand Down Expand Up @@ -4119,7 +4119,7 @@ cmd_exists(char_u *name)
cmdmod_info_T *entry;

target.name = (char *)name;
target.minlen = 0; // not used, see cmp_cmdmod_info()
target.minlen = STRLEN(name);
target.has_count = FALSE;

// Check command modifiers.
Expand Down Expand Up @@ -5993,6 +5993,10 @@ get_command_name(expand_T *xp UNUSED, int idx)
{
if (idx >= (int)CMD_SIZE)
return expand_user_command_name(idx);
// the following are no real commands
if (STRNCMP(cmdnames[idx].cmd_name, "{", 1) == 0 ||
STRNCMP(cmdnames[idx].cmd_name, "}", 1) == 0)
return (char_u *)"";
return cmdnames[idx].cmd_name;
}

Expand Down
21 changes: 21 additions & 0 deletions src/testdir/test_cmdline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3870,4 +3870,25 @@ func Test_term_option()
let &cpo = _cpo
endfunc

func Test_ex_command_completion()
" required for :*
set cpo+=*
let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
" :++ and :-- are only valid in Vim9 Script context, so they can be ignored
call assert_equal(['++', '--'], sort(list))
call assert_equal(1, exists(':k'))
call assert_equal(0, exists(':ke'))
call assert_equal(1, exists(':kee'))
call assert_equal(1, exists(':keep'))
call assert_equal(1, exists(':keepm'))
call assert_equal(1, exists(':keepma'))
call assert_equal(1, exists(':keepmar'))
call assert_equal(1, exists(':keepmark'))
call assert_equal(2, exists(':keepmarks'))
call assert_equal(2, exists(':keepalt'))
call assert_equal(2, exists(':keepjumps'))
call assert_equal(2, exists(':keeppatterns'))
set cpo-=*
endfunc

" vim: shiftwidth=2 sts=2 expandtab

0 comments on commit 9e3734e

Please sign in to comment.