codekingpro/portable-devtools
114k
1" Vim plugin for using Vim as manpager.2" Maintainer: Enno Nagel <ennonagel+vim@gmail.com>3" Last Change: 2024 Jul 034" 2026 Mar 22 by Vim Project: strip OSC 9 sequences (#19787)5" 2026 Mar 24 by Vim Project: strip Bell char: Ctrl-G (#19807)6 7if exists('g:loaded_manpager_plugin')8 finish9endif10let g:loaded_manpager_plugin = 111 12" Set up the current buffer (likely read from stdin) as a manpage13command MANPAGER call s:ManPager()14 15function s:ManPager()16 " global options, keep these to a minimum to avoid side effects17 if &compatible18 set nocompatible19 endif20 if exists('+viminfofile')21 set viminfofile=NONE22 endif23 syntax on24 25 " Ensure text width matches window width26 setlocal foldcolumn& nofoldenable nonumber norelativenumber27 28 " In case Vim was invoked with -M29 setlocal modifiable30 31 " Emulate 'col -b'32 exe 'silent! keepj keepp %s/\v(.)\b\ze\1?//e' .. (&gdefault ? '' : 'g')33 34 " Remove ansi sequences35 exe 'silent! keepj keepp %s/\v\e\[%(%(\d;)?\d{1,2})?[mK]//e' .. (&gdefault ? '' : 'g')36 37 " Remove OSC 8 hyperlink sequences: \e]8;;...\e\ or \e]8;;...<BEL>38 exe 'silent! keepj keepp %s/\v\e\]8;[^\x07\e]*%(%x07|\e\\)//e' .. (&gdefault ? '' : 'g')39 40 " Remove empty lines above the header41 call cursor(1, 1)42 let n = search(".*(.*)", "c")43 if n > 144 exe "1," . n-1 . "d"45 endif46 47 " Finished preprocessing the buffer, prevent any further modifications48 setlocal nomodified nomodifiable49 50 " Make this an unlisted, readonly scratch buffer51 setlocal buftype=nofile noswapfile bufhidden=hide nobuflisted readonly52 53 " Set filetype to man even if ftplugin is disabled54 setlocal filetype=man55 runtime ftplugin/man.vim56endfunction57 