2016-04-30 14:15:54 +02:00
|
|
|
" Vim plugin for using Vim as manpager.
|
|
|
|
" Maintainer: Enno Nagel <ennonagel+vim@gmail.com>
|
2024-07-04 13:37:10 +02:00
|
|
|
" Last Change: 2024 Jul 03
|
2022-10-28 20:47:54 +01:00
|
|
|
|
|
|
|
if exists('g:loaded_manpager_plugin')
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_manpager_plugin = 1
|
2016-04-30 14:15:54 +02:00
|
|
|
|
2022-06-17 15:42:40 +01:00
|
|
|
" Set up the current buffer (likely read from stdin) as a manpage
|
|
|
|
command MANPAGER call s:ManPager()
|
2016-04-30 14:15:54 +02:00
|
|
|
|
2022-06-06 20:52:59 +01:00
|
|
|
function s:ManPager()
|
|
|
|
" global options, keep these to a minimum to avoid side effects
|
|
|
|
if &compatible
|
|
|
|
set nocompatible
|
|
|
|
endif
|
2018-02-09 22:00:53 +01:00
|
|
|
if exists('+viminfofile')
|
|
|
|
set viminfofile=NONE
|
2016-04-30 14:15:54 +02:00
|
|
|
endif
|
2022-06-17 15:42:40 +01:00
|
|
|
syntax on
|
2016-04-30 14:15:54 +02:00
|
|
|
|
2022-06-17 15:42:40 +01:00
|
|
|
" Ensure text width matches window width
|
|
|
|
setlocal foldcolumn& nofoldenable nonumber norelativenumber
|
|
|
|
|
|
|
|
" In case Vim was invoked with -M
|
|
|
|
setlocal modifiable
|
2016-04-30 14:15:54 +02:00
|
|
|
|
2018-02-09 22:00:53 +01:00
|
|
|
" Emulate 'col -b'
|
2023-08-09 18:00:36 +02:00
|
|
|
exe 'silent! keepj keepp %s/\v(.)\b\ze\1?//e' .. (&gdefault ? '' : 'g')
|
2021-08-14 21:25:52 +02:00
|
|
|
|
|
|
|
" Remove ansi sequences
|
2023-08-09 18:00:36 +02:00
|
|
|
exe 'silent! keepj keepp %s/\v\e\[%(%(\d;)?\d{1,2})?[mK]//e' .. (&gdefault ? '' : 'g')
|
2018-02-09 22:00:53 +01:00
|
|
|
|
|
|
|
" Remove empty lines above the header
|
|
|
|
call cursor(1, 1)
|
|
|
|
let n = search(".*(.*)", "c")
|
|
|
|
if n > 1
|
|
|
|
exe "1," . n-1 . "d"
|
|
|
|
endif
|
2016-04-30 14:15:54 +02:00
|
|
|
|
2022-06-17 15:42:40 +01:00
|
|
|
" Finished preprocessing the buffer, prevent any further modifications
|
|
|
|
setlocal nomodified nomodifiable
|
|
|
|
|
2024-07-04 13:37:10 +02:00
|
|
|
" Make this an unlisted, readonly scratch buffer
|
|
|
|
setlocal buftype=nofile noswapfile bufhidden=hide nobuflisted readonly
|
|
|
|
|
2022-06-17 15:42:40 +01:00
|
|
|
" Set filetype to man even if ftplugin is disabled
|
2022-10-03 18:04:35 +01:00
|
|
|
setlocal filetype=man
|
2022-06-17 15:42:40 +01:00
|
|
|
runtime ftplugin/man.vim
|
2016-04-30 14:15:54 +02:00
|
|
|
endfunction
|