diff src/usercmd.c @ 29479:5c390aa28f44 v9.0.0081

patch 9.0.0081: command line completion of user command may have duplicates Commit: https://github.com/vim/vim/commit/c2842adfb2ca0637f13e2793fefa18e7818684f9 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jul 26 17:23:47 2022 +0100 patch 9.0.0081: command line completion of user command may have duplicates Problem: Command line completion of user command may have duplicates. (Dani Dickstein) Solution: Skip global user command if an identical buffer-local one is defined. (closes #10797)
author Bram Moolenaar <Bram@vim.org>
date Tue, 26 Jul 2022 18:30:03 +0200
parents 48b086982c01
children 578e71f924fe
line wrap: on
line diff
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -363,9 +363,19 @@ get_user_commands(expand_T *xp UNUSED, i
 
     if (idx < buf->b_ucmds.ga_len)
 	return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
+
     idx -= buf->b_ucmds.ga_len;
     if (idx < ucmds.ga_len)
-	return USER_CMD(idx)->uc_name;
+    {
+	int	i;
+	char_u  *name = USER_CMD(idx)->uc_name;
+
+	for (i = 0; i < buf->b_ucmds.ga_len; ++i)
+	    if (STRCMP(name, USER_CMD_GA(&buf->b_ucmds, i)->uc_name) == 0)
+		// global command is overruled by buffer-local one
+		return (char_u *)"";
+	return name;
+    }
     return NULL;
 }