From 4bf170d79d1147d391a8bc1d382bb0af51f30bb3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Apr 2026 22:59:22 +0800 Subject: [PATCH] fix(help): show error when using :help! with nothing at cursor #38775 It's possible to still show the old Easter egg, but then the user won't know about the new feature, so showing E349 is better. (cherry picked from commit 9705a1c13b04c20a6b8eb1f57d543f4d08240876) --- src/nvim/errors.h | 1 + src/nvim/help.c | 4 ++++ src/nvim/normal.c | 2 -- test/functional/ex_cmds/help_spec.lua | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/nvim/errors.h b/src/nvim/errors.h index 575ebe2e52..4a38322040 100644 --- a/src/nvim/errors.h +++ b/src/nvim/errors.h @@ -63,6 +63,7 @@ EXTERN const char e_nogroup[] INIT(= N_("E28: No such highlight group name: %s") EXTERN const char e_noinstext[] INIT(= N_("E29: No inserted text yet")); EXTERN const char e_nolastcmd[] INIT(= N_("E30: No previous command line")); EXTERN const char e_nomap[] INIT(= N_("E31: No such mapping")); +EXTERN const char e_noident[] INIT(= N_("E349: No identifier under cursor")); EXTERN const char e_nomatch[] INIT(= N_("E479: No match")); EXTERN const char e_nomatch2[] INIT(= N_("E480: No match: %s")); EXTERN const char e_noname[] INIT(= N_("E32: No file name")); diff --git a/src/nvim/help.c b/src/nvim/help.c index 4babd8e4fc..2928647e6b 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -114,6 +114,10 @@ void ex_help(exarg_T *eap) } api_free_object(res); api_clear_error(&err); + if (allocated_arg == NULL) { + emsg(_(e_noident)); + return; + } } // Check if there is a match for the argument. diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 3f464fb6ce..464cc8ce6b 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -132,8 +132,6 @@ static inline void normal_state_init(NormalState *s) // n_*(): functions called to handle Normal mode commands. // v_*(): functions called to handle Visual mode commands. -static const char *e_noident = N_("E349: No identifier under cursor"); - /// Function to be called for a Normal or Visual mode command. /// The argument is a cmdarg_T. typedef void (*nv_func_T)(cmdarg_T *cap); diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua index 1c55ddf3b0..a57d43d34e 100644 --- a/test/functional/ex_cmds/help_spec.lua +++ b/test/functional/ex_cmds/help_spec.lua @@ -156,6 +156,10 @@ describe(':help', function() -- n.command [[set keywordprg=:help]] -- Failure modes: + set_lines '' + cursor(0, { 1, 1 }) + t.matches('E349: No identifier under cursor', t.pcall_err(n.exec, [[:help!]])) + set_lines 'xxxxxxxxx' cursor(0, { 1, 4 }) t.matches('E149: No help for xxxxxxxxx', t.pcall_err(n.exec, [[:help!]]))