Attached is a modified patch from justinmk for neovim that allows other
ex-commands besides :help to be used in keywordprg.

E.g.

    ru plugin/manpager.vim
    set keywordprg=:Man

would open man pages in a split when 'K' is pressed over a keyword
instead of opening it in a pager, instead of relying on hacky maps from
plugins.

The original functionality is otherwise preserved.

My C isn't particularly good, but I tried to fit the patch to the
existing code style and to make as few changes as possible.

Especially the changes from L5560 to L5559 could probably be written
better.

Best regards,
Nelo-T. Wallus

--
Viktoriastrasse 22
76133 Karlsruhe
Nr.:    0721 / 96 55 63 95
Handy:  0178 / 53 17 067
Web:    https://nelo.wallus.de/
/"\  ASCII Ribbon Campaign
\ /  - against HTML emails
 X   - against proprietory attachments
/ \  http://en.wikipedia.org/wiki/ASCII_Ribbon_Campaign

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
>From a7300f13c798f5913ba7359e0c417e18ee4b3351 Mon Sep 17 00:00:00 2001
From: Nelo Wallus <[email protected]>
Date: Sat, 21 May 2016 08:06:12 +0200
Subject: [PATCH] Allow ex commands in keywordprg

Modified patch from justinmk neovim 998d0ffc09d5c7358db62dc88c2e2b87622f60b5

Neovim-specific changes were removed, minor changes to fit to the
existing code style.

Allows all ex commands to be used in keywordprg instead of just :help.

Original:
https://github.com/neovim/neovim/pull/1878/commits/998d0ffc09d5c7358db62dc88c2e2b87622f60b5
---
 runtime/doc/options.txt |  8 +++++---
 runtime/doc/various.txt | 11 +++++++----
 src/normal.c            | 16 ++++++++++------
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index aefbdbf..cdca1df 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -4594,9 +4594,11 @@ A jump table for the options with a short description can be found at |Q_op|.
 	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 "man" is used, Vim will automatically translate a count for the
-	"K" command to a section number.  Also for "man -s", in which case the
-	"-s" is removed when there is no count.
+	When the first character is ":", the command is invoked as a Vim
+	command prefixed with [count].
+	When "man", "man -s" or an ex command is used, Vim will automatically
+	translate a count for the "K" command and pass it as the first
+	argument.
 	See |option-backslash| about including spaces and backslashes.
 	Example: >
 		:set keywordprg=man\ -s
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index 7510210..f846537 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -607,13 +607,16 @@ K			Run a program to lookup the keyword under the
 			directory of Vim.  It is called 'ref' and does a
 			simple spelling check.
 			Special cases:
+			- If 'keywordprg' begins with ":" it is invoked as
+			  a Vim command with [count].
 			- If 'keywordprg' is empty, the ":help" command is
 			  used.  It's a good idea to include more characters
 			  in 'iskeyword' then, to be able to find more help.
-			- When 'keywordprg' is equal to "man", a count before
-			  "K" is inserted after the "man" command and before
-			  the keyword.  For example, using "2K" while the
-			  cursor is on "mkdir", results in: >
+			- When 'keywordprg' is equal to "man" or starts with
+			  ":", a [count] before "K" is inserted after
+			  keywordprg and before the keyword.  For example,
+			  using "2K" while the cursor is on "mkdir", results
+			  in: >
 				!man 2 mkdir
 <			- When 'keywordprg' is equal to "man -s", a count
 			  before "K" is inserted after the "-s".  If there is
diff --git a/src/normal.c b/src/normal.c
index 7c15c15..1030a43 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -5488,7 +5488,7 @@ nv_ident(cmdarg_T *cap)
     char_u	*newbuf;
     char_u	*p;
     char_u	*kp;		/* value of 'keywordprg' */
-    int		kp_help;	/* 'keywordprg' is ":help" */
+    int		kp_ex;		/* 'keywordprg' is an ex command */
     int		n = 0;		/* init for GCC */
     int		cmdchar;
     int		g_cmd;		/* "g" command */
@@ -5534,8 +5534,7 @@ nv_ident(cmdarg_T *cap)
      * double the length of the word.  p_kp / curbuf->b_p_kp could be added
      * and some numbers. */
     kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp);
-    kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0
-						 || STRCMP(kp, ":help") == 0);
+    kp_ex = (STRNCMP(kp, ":", 1) == 0);
     buf = alloc((unsigned)(n * 2 + 30 + STRLEN(kp)));
     if (buf == NULL)
 	return;
@@ -5560,8 +5559,13 @@ nv_ident(cmdarg_T *cap)
 	    break;
 
 	case 'K':
-	    if (kp_help)
-		STRCPY(buf, "he! ");
+	    if (kp_ex) {
+		if (cap->count0 != 0) {
+		    sprintf(buf, "%s %" PRId64, kp, (cap->count0));
+		} else
+		    STRCAT(buf, kp);
+		STRCAT(buf, " ");
+	    }
 	    else
 	    {
 		/* An external command will probably use an argument starting
@@ -5625,7 +5629,7 @@ nv_ident(cmdarg_T *cap)
     /*
      * Now grab the chars in the identifier
      */
-    if (cmdchar == 'K' && !kp_help)
+    if (cmdchar == 'K' && !kp_ex)
     {
 	/* Escape the argument properly for a shell command */
 	ptr = vim_strnsave(ptr, n);
-- 
2.8.1

Raspunde prin e-mail lui