vim-patch:9.1.0748: :keep* commmands are sometimes misidentified as :k

Problem:  The :keep{alt,jumps,marks,patterns} commmands are sometimes
          misidentified as :k.
Solution: Make sure one_letter_cmd() only returns true for :k and not
          other :keep* commands (Doug Kearns).

This currently manifests as missing completion for :keep* commands and
incorrect results from fullcommand().

E.g., fullcommand("keepmarks") returns "k" rather than "keepmarks".

The correct command, however, is executed as command modifiers are
handled specially in do_one_cmd() rather than using find_ex_command().

Fix exists(':k') so that it returns 2 for a full match.

closes: vim/vim#15742

ea84202372

Cherry-pick Test_ex_command_completion() from patch 9.1.0624.

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
zeertzjq
2025-08-09 07:32:55 +08:00
parent a0d94ac469
commit 70bb7999f7
4 changed files with 79 additions and 2 deletions

View File

@@ -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++;