feat(help): super K (":help!") guesses tag at cursor #36205

Problem:
`K` in help files may fail in some noisy text. Example:

      (`fun(config: vim.lsp.ClientConfig): boolean`)
                            ^cursor

Solution:
- `:help!` (bang, no args) activates DWIM behavior: tries `<cWORD>`,
  then trims punctuation until a valid tag is found.
- Set `keywordprg=:help!` by default.
- Does not affect `CTRL-]`, that is still fully "tags" based.
This commit is contained in:
Justin M. Keyes
2026-03-15 19:02:49 -04:00
committed by GitHub
parent 747da13f44
commit 16f7440cc7
14 changed files with 495 additions and 74 deletions

View File

@@ -3834,20 +3834,27 @@ vim.go.keymodel = vim.o.keymodel
vim.go.km = vim.go.keymodel
--- Program to use for the `K` command. Environment variables are
--- expanded `:set_env`. ":help" may be used to access the Vim internal
--- help. (Note that previously setting the global option to the empty
--- value did this, which is now deprecated.)
--- When the first character is ":", the command is invoked as a Vim
--- Ex command prefixed with [count].
--- When "man" or "man -s" is used, Vim will automatically translate
--- a [count] for the "K" command to a section number.
--- expanded `:set_env`.
---
--- Special cases:
--- - ":help" opens the `word` at cursor using `:help`. (Note that
--- previously setting the global option to the empty value did this,
--- which is now deprecated.)
--- - ":help!" performs `:help!` (DWIM) on the `WORD` at cursor.
--- - If the value starts with ":", it is invoked as an Ex command
--- prefixed with [count].
--- - If "man" or "man -s", [count] is the manpage section number.
---
--- See `option-backslash` about including spaces and backslashes.
---
--- Example:
---
--- ```vim
--- set keywordprg=:help!
--- set keywordprg=man\ -s
--- set keywordprg=:Man
--- ```
---
--- This option cannot be set from a `modeline` or in the `sandbox`, for
--- security reasons.
---