From 84ae70c172596a712a8d22fa3442d37632cc2d37 Mon Sep 17 00:00:00 2001 From: Yochem van Rosmalen Date: Fri, 1 May 2026 12:28:16 +0200 Subject: [PATCH] fix(help): fix CTRL character issue for :help {subject} #39537 Problem: The argument to `:help` is normalized to fit the general tag format. I.e. i^U-default, iCTRL-U-default and i_CTRL_U-default should all point to the i_CTRL_U-default tag. Our normalization adds an underscore around the CTRL keycode, e.g. iCTRL-GCTRL-J becomes i_CTRL-G_CTRL-J. That's not necessary if the following part starts with a dash, like the case of iCTRL-U-default. Solution: Do not insert an underscore if the following character is a dash/minus (-). --- runtime/lua/vim/_core/help.lua | 2 +- test/functional/ex_cmds/help_spec.lua | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/_core/help.lua b/runtime/lua/vim/_core/help.lua index 87f9d462de..cc410daf17 100644 --- a/runtime/lua/vim/_core/help.lua +++ b/runtime/lua/vim/_core/help.lua @@ -108,7 +108,7 @@ function M.escape_subject(word) -- E.g. 'iCTRL-GCTRL-J' --> 'i_CTRL-G_CTRL-J' -- Only exception: 'CTRL-{character}' word = word:gsub('([^_])CTRL%-', '%1_CTRL-') - word = word:gsub('(CTRL%-[^{])([^_\\])', '%1_%2') + word = word:gsub('(CTRL%-[^{])([^-_\\])', '%1_%2') -- Skip function arguments -- E.g. 'abs({expr})' --> 'abs' diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua index ffec9e50b0..7edb0556c5 100644 --- a/test/functional/ex_cmds/help_spec.lua +++ b/test/functional/ex_cmds/help_spec.lua @@ -130,6 +130,7 @@ describe(':help', function() check_tag('help <>', '*<>*') check_tag([[help i^x^y]], '*i_CTRL-X_CTRL-Y*') check_tag([[help CTRL-\_CTRL-N]], [[*CTRL-\_CTRL-N*]]) + check_tag([[help i_CTRL-U-default]], [[*i_CTRL-U-default*]]) check_tag([[exe "help i\\"]], [[*i_CTRL-\_CTRL-G*]]) check_tag([[exe "help \"]], '*CTRL-V*')