diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 0532472a06..e06ab4c275 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2020,6 +2020,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_tab: case CMD_tabdo: case CMD_topleft: + case CMD_unsilent: case CMD_verbose: case CMD_vertical: case CMD_windo: diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index cae35ed2e2..3f49252c95 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3025,13 +3025,16 @@ static void append_command(const char *cmd) } /// Return true and set "*idx" if "p" points to a one letter command. -/// - The 'k' command can directly be followed by any character. +/// - The 'k' command can directly be followed by any character +/// but :keepa[lt] is another command, as are :keepj[umps], +/// :kee[pmarks] and :keepp[atterns]. /// - The 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r' /// but :sre[wind] is another command, as are :scr[iptnames], /// :scs[cope], :sim[alt], :sig[ns] and :sil[ent]. static int one_letter_cmd(const char *p, cmdidx_T *idx) { - if (*p == 'k') { + if (p[0] == 'k' + && (p[1] != 'e' || (p[1] == 'e' && p[2] != 'e'))) { *idx = CMD_k; return true; } @@ -3064,6 +3067,9 @@ char *find_ex_command(exarg_T *eap, int *full) char *p = eap->cmd; if (one_letter_cmd(p, &eap->cmdidx)) { p++; + if (full != NULL) { + *full = true; + } } else { while (ASCII_ISALPHA(*p)) { p++; diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 2cad916624..cddc1d777c 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -1244,6 +1244,10 @@ func Test_cmdline_complete_various() call feedkeys(":ka\\\"\", 'xt') call assert_equal("\"ka\", @:) + " completion for :keepmarks command + call feedkeys(":kee edi\\\"\", 'xt') + call assert_equal("\"kee edit", @:) + " completion for short version of the :s command call feedkeys(":sI \\\"\", 'xt') call assert_equal("\"sI \", @:) @@ -4350,6 +4354,28 @@ 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([], sort(list)) + call assert_equal(2, 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 + func Test_cd_bslash_completion_windows() CheckMSWindows let save_shellslash = &shellslash diff --git a/test/old/testdir/test_cmdmods.vim b/test/old/testdir/test_cmdmods.vim new file mode 100644 index 0000000000..c4ad5c6094 --- /dev/null +++ b/test/old/testdir/test_cmdmods.vim @@ -0,0 +1,59 @@ +" Test for all command modifiers in + +let s:luaeval_cmdmods =<< trim END + vim.iter(loadfile('../../../src/nvim/ex_cmds.lua')()):map(function(cmd) + if cmd.func == 'ex_wrongmodifier' or cmd.command == 'hide' then + return cmd.command + else + return nil + end + end):totable() +END +let s:cmdmods = [] + +func s:get_cmdmods() + if empty(s:cmdmods) + let s:cmdmods = luaeval(s:luaeval_cmdmods->join("\n")) + endif + return s:cmdmods +endfunc + +func Test_keep_cmdmods_names() + call assert_equal('k', fullcommand(':k')) + call assert_equal('k', fullcommand(':ke')) + call assert_equal('keepmarks', fullcommand(':kee')) + call assert_equal('keepmarks', fullcommand(':keep')) + call assert_equal('keepmarks', fullcommand(':keepm')) + call assert_equal('keepmarks', fullcommand(':keepma')) + call assert_equal('keepmarks', fullcommand(':keepmar')) + call assert_equal('keepmarks', fullcommand(':keepmark')) + call assert_equal('keepmarks', fullcommand(':keepmarks')) + call assert_equal('keepalt', fullcommand(':keepa')) + call assert_equal('keepalt', fullcommand(':keepal')) + call assert_equal('keepalt', fullcommand(':keepalt')) + call assert_equal('keepjumps', fullcommand(':keepj')) + call assert_equal('keepjumps', fullcommand(':keepju')) + call assert_equal('keepjumps', fullcommand(':keepjum')) + call assert_equal('keepjumps', fullcommand(':keepjump')) + call assert_equal('keepjumps', fullcommand(':keepjumps')) + call assert_equal('keeppatterns', fullcommand(':keepp')) + call assert_equal('keeppatterns', fullcommand(':keeppa')) + call assert_equal('keeppatterns', fullcommand(':keeppat')) + call assert_equal('keeppatterns', fullcommand(':keeppatt')) + call assert_equal('keeppatterns', fullcommand(':keeppatte')) + call assert_equal('keeppatterns', fullcommand(':keeppatter')) + call assert_equal('keeppatterns', fullcommand(':keeppattern')) + call assert_equal('keeppatterns', fullcommand(':keeppatterns')) +endfunc + +func Test_cmdmod_completion() + for mod in s:get_cmdmods() + let cmd = $'{mod} ed' + if mod == 'filter' + let cmd = $'{mod} /pattern/ ed' + endif + call assert_equal('edit', getcompletion(cmd, 'cmdline')[0]) + endfor +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_exists.vim b/test/old/testdir/test_exists.vim index 62c66192ef..589fc54782 100644 --- a/test/old/testdir/test_exists.vim +++ b/test/old/testdir/test_exists.vim @@ -105,6 +105,13 @@ func Test_exists() " Internal command with a count call assert_equal(0, exists(':3buffer')) + " Valid internal command (full match) + call assert_equal(2, exists(':k')) + " Non-existing internal command (':k' with arg 'e') + call assert_equal(0, exists(':ke')) + " Valid internal command (partial match) + call assert_equal(1, exists(':kee')) + " User defined command (full match) command! MyCmd :echo 'My command' call assert_equal(2, exists(':MyCmd'))