blob: be6e30b70f5807650e3b4a2294c8a8123d224ba9 [file] [log] [blame]
Bram Moolenaarb20545f2016-04-30 14:15:54 +02001" Vim plugin for using Vim as manpager.
2" Maintainer: Enno Nagel <ennonagel+vim@gmail.com>
Bram Moolenaar06d2d382016-05-20 17:24:11 +02003" Last Change: 2016 May 20
Bram Moolenaarb20545f2016-04-30 14:15:54 +02004
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
Bram Moolenaar91c49372016-05-08 09:50:29 +020023 let page_sec = matchlist(tolower(manpage), '^' . pagesec_pattern . '$')
Bram Moolenaarb20545f2016-04-30 14:15:54 +020024
25 bwipe!
26
27 setlocal filetype=man
Bram Moolenaar06d2d382016-05-20 17:24:11 +020028 exe 'Man' page_sec[2] page_sec[1]
Bram Moolenaarb20545f2016-04-30 14:15:54 +020029endfunction