xref: /vim-8.2.3635/runtime/plugin/manpager.vim (revision cb03397a)
1" Vim plugin for using Vim as manpager.
2" Maintainer: Enno Nagel <[email protected]>
3" Last Change: 2016 May 20
4
5" $MAN_PN is supposed to be set by MANPAGER, see ":help manpager.vim".
6if empty($MAN_PN)
7  finish
8endif
9
10command! -nargs=0 MANPAGER call s:MANPAGER() | delcommand MANPAGER
11
12function! s:MANPAGER()
13  let page_pattern = '\v\w+%([-_.]\w+)*'
14  let sec_pattern = '\v\w+%(\+\w+)*'
15  let pagesec_pattern = '\v(' . page_pattern . ')\((' . sec_pattern . ')\)'
16
17  if $MAN_PN is '1'
18    let manpage = matchstr( getline(1), '^' . pagesec_pattern )
19  else
20    let manpage = expand('$MAN_PN')
21  endif
22
23  let page_sec = matchlist(tolower(manpage), '^' . pagesec_pattern  . '$')
24
25  bwipe!
26
27  setlocal filetype=man
28  exe 'Man' page_sec[2] page_sec[1]
29endfunction
30