| 
									
										
										
										
											2016-04-30 14:15:54 +02:00
										 |  |  | " Vim plugin for using Vim as manpager. | 
					
						
							|  |  |  | " Maintainer: Enno Nagel <ennonagel+vim@gmail.com> | 
					
						
							| 
									
										
										
										
											2022-10-28 20:47:54 +01:00
										 |  |  | " Last Change: 2022 Oct 17 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  |   " Make this an unlisted, readonly scratch buffer | 
					
						
							|  |  |  |   setlocal buftype=nofile noswapfile bufhidden=hide nobuflisted readonly | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " 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' | 
					
						
							| 
									
										
										
										
											2021-08-14 21:25:52 +02:00
										 |  |  |   silent! keepj keepp %s/\v(.)\b\ze\1?//ge | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " Remove ansi sequences | 
					
						
							|  |  |  |   silent! keepj keepp %s/\v\e\[%(%(\d;)?\d{1,2})?[mK]//ge | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " 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 |