Mercurial > vim
changeset 9037:d07035f84f0d v7.4.1804
commit https://github.com/vim/vim/commit/b20545f2a718d4f19c3f609fd11c0ca4eff450ce
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 30 14:15:54 2016 +0200
patch 7.4.1804
Problem: Can't use Vim as MANPAGER.
Solution: Add manpager.vim. (Enno Nagel, closes https://github.com/vim/vim/issues/491)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Apr 2016 14:30:05 +0200 |
parents | f15a6ae572a5 |
children | 515717037fc1 |
files | runtime/plugin/manpager.vim src/version.c |
diffstat | 2 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/runtime/plugin/manpager.vim @@ -0,0 +1,29 @@ +" Vim plugin for using Vim as manpager. +" Maintainer: Enno Nagel <ennonagel+vim@gmail.com> +" Last Change: 2016 Apr 30 + +" $MAN_PN is supposed to be set by MANPAGER, see ":help manpager.vim". +if empty($MAN_PN) + finish +endif + +command! -nargs=0 MANPAGER call s:MANPAGER() | delcommand MANPAGER + +function! s:MANPAGER() + let page_pattern = '\v\w+%([-_.]\w+)*' + let sec_pattern = '\v\w+%(\+\w+)*' + let pagesec_pattern = '\v(' . page_pattern . ')\((' . sec_pattern . ')\)' + + if $MAN_PN is '1' + let manpage = matchstr( getline(1), '^' . pagesec_pattern ) + else + let manpage = expand('$MAN_PN') + endif + + let page_sec = matchlist( manpage, '^' . pagesec_pattern . '$') + + bwipe! + + setlocal filetype=man + exe 'Man' page_sec[3] page_sec[1] +endfunction