runtime: configure keywordpg for some file types (#5566)

Commit: 
https://github.com/vim/vim/commit/2f25e40b1f545f4aa38377f0c25effb112b5d1ef
Author: Enno <konf...@users.noreply.github.com>
Date:   Wed Aug 23 21:27:50 2023 +0200

    runtime: configure keywordpg for some file types 
(https://github.com/vim/vim/issues/5566)
    
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/ftplugin/gpg.vim b/runtime/ftplugin/gpg.vim
index 3f890e58f..9e00daed6 100644
--- a/runtime/ftplugin/gpg.vim
+++ b/runtime/ftplugin/gpg.vim
@@ -15,5 +15,22 @@ let b:undo_ftplugin = "setl com< cms< fo<"
 
 setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
 
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+--' . 
<q-args> . ' '' --hilite-search" man ' . 'gpg' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape('^\s+--' . <q-args> . ' ', '\') . ''' --hilite-search" man ' . 'gpg'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
+
 let &cpo = s:cpo_save
 unlet s:cpo_save
+
diff --git a/runtime/ftplugin/modconf.vim b/runtime/ftplugin/modconf.vim
index c8e76b538..09ad54b64 100644
--- a/runtime/ftplugin/modconf.vim
+++ b/runtime/ftplugin/modconf.vim
@@ -16,5 +16,21 @@ let b:undo_ftplugin = "setl com< cms< inc< fo<"
 setlocal comments=:# commentstring=#\ %s include=^\s*include
 setlocal formatoptions-=t formatoptions+=croql
 
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s{,8}' . 
<q-args> . ' '' --hilite-search" man ' . 'modprobe.d' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape('^\s{,8}' . <q-args> . ' ', '\') . ''' --hilite-search" man ' . 
'modprobe.d'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
+
 let &cpo = s:cpo_save
 unlet s:cpo_save
diff --git a/runtime/ftplugin/muttrc.vim b/runtime/ftplugin/muttrc.vim
index c8ad0f2ec..bd0136715 100644
--- a/runtime/ftplugin/muttrc.vim
+++ b/runtime/ftplugin/muttrc.vim
@@ -18,5 +18,21 @@ setlocal formatoptions-=t formatoptions+=croql
 
 let &l:include = '^\s*source\>'
 
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+' . 
<q-args> . ' '' --hilite-search" man ' . 'muttrc' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe 'term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape('^\s+' . <q-args> . ' ', '\') . ''' --hilite-search" man ' . 'muttrc'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
+
 let &cpo = s:cpo_save
 unlet s:cpo_save
diff --git a/runtime/ftplugin/readline.vim b/runtime/ftplugin/readline.vim
index 524eeb736..c81d0f2f6 100644
--- a/runtime/ftplugin/readline.vim
+++ b/runtime/ftplugin/readline.vim
@@ -30,6 +30,22 @@ if (has("gui_win32") || has("gui_gtk")) && 
!exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+' . 
<q-args> . ' '' --hilite-search" man ' . '3 readline' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe 'term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape('^\s+' . <q-args> . ' ', '\') . ''' --hilite-search" man ' . '3 readline'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
+
 let &cpo = s:cpo_save
 unlet s:cpo_save
 
diff --git a/runtime/ftplugin/sh.vim b/runtime/ftplugin/sh.vim
index b6fdb8f3e..7106bf915 100644
--- a/runtime/ftplugin/sh.vim
+++ b/runtime/ftplugin/sh.vim
@@ -41,6 +41,19 @@ if (has("gui_win32") || has("gui_gtk")) && 
!exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
+if (exists('b:is_bash') && (b:is_bash == 1)) ||
+      \ (exists('b:is_sh') && (b:is_sh == 1))
+  if !has('gui_running') && executable('less')
+    command! -buffer -nargs=1 Help silent exe '!bash -c "{ help "<args>" 
2>/dev/null || man "<args>"; } | LESS= less"' | redraw!
+  elseif has('terminal')
+    command! -buffer -nargs=1 Help silent exe ':term bash -c "help "<args>" 
2>/dev/null || man "<args>""'
+  else
+    command! -buffer -nargs=1 Help echo system('bash -c "help <args>" 
2>/dev/null || man "<args>"')
+  endif
+  setlocal keywordprg=:Help
+  let b:undo_ftplugin .= '| setlocal keywordprg<'
+endif
+
 " Restore the saved compatibility options.
 let &cpo = s:save_cpo
 unlet s:save_cpo
diff --git a/runtime/ftplugin/sshconfig.vim b/runtime/ftplugin/sshconfig.vim
index d933ce052..214e4928a 100644
--- a/runtime/ftplugin/sshconfig.vim
+++ b/runtime/ftplugin/sshconfig.vim
@@ -1,7 +1,7 @@
 " Vim filetype plugin file
-" Language:             OpenSSH client configuration file
-" Previous Maintainer:  Nikolai Weibull <n...@bitwi.se>
-" Latest Revision:      2008-07-09
+" Language:         OpenSSH client configuration file
+" Previous Maintainer:       Nikolai Weibull <n...@bitwi.se>
+" Latest Revision:  2008-07-09
 
 if exists("b:did_ftplugin")
   finish
@@ -11,9 +11,24 @@ let b:did_ftplugin = 1
 let s:cpo_save = &cpo
 set cpo&vim
 
-let b:undo_ftplugin = "setl com< cms< fo<"
-
 setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
+let b:undo_ftplugin = 'setlocal com< cms< fo<'
+
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+' . 
<q-args> . '$'' --hilite-search" man ' . 'ssh_config' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe 'term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape('^\s+' . <q-args> . '$', '\') . ''' --hilite-search" man ' . 'ssh_config'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
 
 let &cpo = s:cpo_save
 unlet s:cpo_save
diff --git a/runtime/ftplugin/sudoers.vim b/runtime/ftplugin/sudoers.vim
index 38dbf559e..65cf2d820 100644
--- a/runtime/ftplugin/sudoers.vim
+++ b/runtime/ftplugin/sudoers.vim
@@ -15,5 +15,21 @@ let b:undo_ftplugin = "setl com< cms< fo<"
 
 setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
 
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern='' ' . <q-args> . 
' '' --hilite-search" man ' . 'sudoers' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape(' ' . <q-args> . ' ', '\') . ''' --hilite-search" man ' . 'sudoers'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
+
 let &cpo = s:cpo_save
 unlet s:cpo_save
diff --git a/runtime/ftplugin/systemd.vim b/runtime/ftplugin/systemd.vim
index 4c5c9a1dc..c0bc6302f 100644
--- a/runtime/ftplugin/systemd.vim
+++ b/runtime/ftplugin/systemd.vim
@@ -7,35 +7,30 @@ if !exists('b:did_ftplugin')
   runtime! ftplugin/dosini.vim
 endif
 
-if !has('unix')
-  finish
-endif
-
-if !has('gui_running')
-  command! -buffer -nargs=1 Sman silent exe '!' . 
KeywordLookup_systemd(<q-args>) | redraw!
-elseif has('terminal')
-  command! -buffer -nargs=1 Sman silent exe 'term ' . 
KeywordLookup_systemd(<q-args>)
-else
-  finish
-endif
-
-if !exists('*KeywordLookup_systemd')
-  function KeywordLookup_systemd(keyword) abort
-    let matches = matchlist(getline(search(' ^\s*\[\s*.+\s*\]\s*$', 'nbWz')), 
' ^\s*\[\s*(\k+).*\]\s*$')
-    if len(matches) > 1
-      let section = matches[1]
-      return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . '=$'' 
--hilite-search" man ' . 'systemd.' . section
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman silent exe '!' . 
KeywordLookup_systemd(<q-args>) | redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman silent exe 'term ' . 
KeywordLookup_systemd(<q-args>)
+  endif
+  if exists(':Sman') == 2
+    if !exists('*KeywordLookup_systemd')
+      function KeywordLookup_systemd(keyword) abort
+        let matches = matchlist(getline(search(' ^\s*\[\s*.+\s*\]\s*$', 
'nbWz')), ' ^\s*\[\s*(\k+).*\]\s*$')
+        if len(matches) > 1
+          let section = matches[1]
+          return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . 
'=$'' --hilite-search" man ' . 'systemd.' . section
+        else
+          return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . 
'=$'' --hilite-search" man ' . 'systemd'
+        endif
+      endfunction
+    endif
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin)
+      let b:undo_ftplugin = 'setlocal keywordprg< iskeyword<'
     else
-      return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . '=$'' 
--hilite-search" man ' . 'systemd'
+      let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
     endif
-  endfunction
-endif
-
-setlocal iskeyword+=-
-setlocal keywordprg=:Sman
-
-if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin)
-  let b:undo_ftplugin = 'setlocal keywordprg< iskeyword<'
-else
-  let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
 endif
diff --git a/runtime/ftplugin/udevrules.vim b/runtime/ftplugin/udevrules.vim
index 6404f6c85..bde9c5dfa 100644
--- a/runtime/ftplugin/udevrules.vim
+++ b/runtime/ftplugin/udevrules.vim
@@ -15,5 +15,21 @@ let b:undo_ftplugin = "setl com< cms< fo<"
 
 setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
 
+if has('unix') && executable('less')
+  if !has('gui_running')
+    command -buffer -nargs=1 Sman
+          \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s{,8}' . 
<q-args> . ' '' --hilite-search" man ' . 'udev' |
+          \ redraw!
+  elseif has('terminal')
+    command -buffer -nargs=1 Sman
+          \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . 
escape('^\s{,8}' . <q-args> . ' ', '\') . ''' --hilite-search" man ' . 'udev'
+  endif
+  if exists(':Sman') == 2
+    setlocal iskeyword+=-
+    setlocal keywordprg=:Sman
+    let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
+  endif
+endif
+
 let &cpo = s:cpo_save
 unlet s:cpo_save

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qZ2yH-00FvG4-Oe%40256bit.org.

Raspunde prin e-mail lui