0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.4618: cmdline completion does not recognize single letter commands

Problem:    Command line completion does not recognize single letter commands.
Solution:   Use the condition from find_ex_command().
This commit is contained in:
Bram Moolenaar 2022-03-24 13:08:36 +00:00
parent 454ce6737c
commit f4f0525c34
2 changed files with 42 additions and 25 deletions

View File

@ -3420,6 +3420,38 @@ skip_option_env_lead(char_u *start)
} }
#endif #endif
/*
* Return TRUE and set "*idx" if "p" points to a one letter command.
* If not in Vim9 script:
* - The 'k' command can directly be followed by any character.
* - 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(char_u *p, cmdidx_T *idx)
{
if (!in_vim9script())
return FALSE;
if (*p == 'k')
{
*idx = CMD_k;
return TRUE;
}
if (p[0] == 's'
&& ((p[1] == 'c' && (p[2] == NUL || (p[2] != 's' && p[2] != 'r'
&& (p[3] == NUL || (p[3] != 'i' && p[4] != 'p')))))
|| p[1] == 'g'
|| (p[1] == 'i' && p[2] != 'm' && p[2] != 'l' && p[2] != 'g')
|| p[1] == 'I'
|| (p[1] == 'r' && p[2] != 'e')))
{
*idx = CMD_substitute;
return TRUE;
}
return FALSE;
}
/* /*
* Find an Ex command by its name, either built-in or user. * Find an Ex command by its name, either built-in or user.
* Start of the name can be found at eap->cmd. * Start of the name can be found at eap->cmd.
@ -3654,30 +3686,10 @@ find_ex_command(
/* /*
* Isolate the command and search for it in the command table. * Isolate the command and search for it in the command table.
* Exceptions:
* - The 'k' command can directly be followed by any character.
* But it is not used in Vim9 script.
* - 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].
* - the "d" command can directly be followed by 'l' or 'p' flag.
*/ */
p = eap->cmd; p = eap->cmd;
if (!vim9 && *p == 'k') if (one_letter_cmd(p, &eap->cmdidx))
{ {
eap->cmdidx = CMD_k;
++p;
}
else if (!vim9
&& p[0] == 's'
&& ((p[1] == 'c' && (p[2] == NUL || (p[2] != 's' && p[2] != 'r'
&& (p[3] == NUL || (p[3] != 'i' && p[4] != 'p')))))
|| p[1] == 'g'
|| (p[1] == 'i' && p[2] != 'm' && p[2] != 'l' && p[2] != 'g')
|| p[1] == 'I'
|| (p[1] == 'r' && p[2] != 'e')))
{
eap->cmdidx = CMD_substitute;
++p; ++p;
} }
else else
@ -3702,6 +3714,8 @@ find_ex_command(
if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#}", *p) != NULL) if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#}", *p) != NULL)
++p; ++p;
len = (int)(p - eap->cmd); len = (int)(p - eap->cmd);
// The "d" command can directly be followed by 'l' or 'p' flag, when
// not in Vim9 script.
if (!vim9 && *eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) if (!vim9 && *eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p'))
{ {
// Check for ":dl", ":dell", etc. to ":deletel": that's // Check for ":dl", ":dell", etc. to ":deletel": that's
@ -3955,10 +3969,11 @@ excmd_get_cmdidx(char_u *cmd, int len)
{ {
cmdidx_T idx; cmdidx_T idx;
for (idx = (cmdidx_T)0; (int)idx < (int)CMD_SIZE; if (!one_letter_cmd(cmd, &idx))
idx = (cmdidx_T)((int)idx + 1)) for (idx = (cmdidx_T)0; (int)idx < (int)CMD_SIZE;
if (STRNCMP(cmdnames[(int)idx].cmd_name, cmd, (size_t)len) == 0) idx = (cmdidx_T)((int)idx + 1))
break; if (STRNCMP(cmdnames[(int)idx].cmd_name, cmd, (size_t)len) == 0)
break;
return idx; return idx;
} }

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4618,
/**/ /**/
4617, 4617,
/**/ /**/