diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 1e40b0e63b..8987d7253e 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -3941,7 +3941,7 @@ A jump table for the options with a short description can be found at |Q_op|. 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]. + and [count] is passed as the first argument, if present. - If "man" or "man -s", [count] is the manpage section number. See |option-backslash| about including spaces and backslashes. diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index 57e739e3fb..5fd55ed3d1 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -523,7 +523,8 @@ user command or autocommand, the script in which it was defined is reported. :tabnew | terminal {program} {keyword} < Special cases: - If 'keywordprg' begins with ":" it is invoked as - a Vim command with [count]. + a Vim command and [count] is passed as the first + argument, if present. - If 'keywordprg' is empty, |:help| is used. - When 'keywordprg' is equal to "man", a [count] before "K" is inserted after the "man" command and diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua index 6d9fa4637e..49170b6cf2 100644 --- a/runtime/lua/vim/_meta/options.lua +++ b/runtime/lua/vim/_meta/options.lua @@ -3849,7 +3849,7 @@ vim.go.km = vim.go.keymodel --- 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]. +--- and [count] is passed as the first argument, if present. --- - If "man" or "man -s", [count] is the manpage section number. --- --- See `option-backslash` about including spaces and backslashes. diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 464cc8ce6b..f17a06fc0f 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3330,10 +3330,11 @@ static size_t nv_K_getcmd(cmdarg_T *cap, char *kp, bool kp_help, bool kp_ex, cha if (kp_ex) { *buflen = 0; // 'keywordprg' is an ex command + *buflen = (size_t)snprintf(buf, bufsize, "%s ", kp); if (cap->count0 != 0) { // Send the count to the ex command. - *buflen = (size_t)snprintf(buf, bufsize, "%" PRId64, (int64_t)(cap->count0)); + *buflen += (size_t)snprintf(buf + *buflen, bufsize - *buflen, + "%" PRId64 " ", (int64_t)cap->count0); } - *buflen += (size_t)snprintf(buf + *buflen, bufsize - *buflen, "%s ", kp); return n; } diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 6da17171c3..5c2c08cfa4 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -5082,7 +5082,7 @@ local options = { 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]. + and [count] is passed as the first argument, if present. - If "man" or "man -s", [count] is the manpage section number. See |option-backslash| about including spaces and backslashes. diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 18cbc0b20b..92b1b789c1 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -1876,14 +1876,13 @@ func Test_normal23_K() set iskeyword-=% set iskeyword-=\| - " Currently doesn't work in Nvim, see #19436 " Test for specifying a count to K - " 1 - " com! -nargs=* Kprog let g:Kprog_Args = - " set keywordprg=:Kprog - " norm! 3K - " call assert_equal('3 version8', g:Kprog_Args) - " delcom Kprog + 1 + com! -nargs=* Kprog let g:Kprog_Args = + set keywordprg=:Kprog + norm! 3K + call assert_equal('3 helphelp', g:Kprog_Args) + delcom Kprog " Only expect "man" to work on Unix if !has("unix") || has('nvim') " Nvim K uses :terminal. #15398