1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-22 17:55:10 +01:00
vim/runtime/plugin/manpager.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.3 KiB
VimL
Raw Normal View History

" Vim plugin for using Vim as manpager.
" Maintainer: Enno Nagel <ennonagel+vim@gmail.com>
" 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
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()
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
endif
2022-06-17 15:42:40 +01:00
syntax on
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
2018-02-09 22:00:53 +01:00
" Emulate 'col -b'
exe 'silent! keepj keepp %s/\v(.)\b\ze\1?//e' .. (&gdefault ? '' : 'g')
2021-08-14 21:25:52 +02:00
" Remove ansi sequences
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
2022-06-17 15:42:40 +01:00
" Finished preprocessing the buffer, prevent any further modifications
setlocal nomodified nomodifiable
" 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
endfunction