HOWTO: Use Vim as a manpager

Vim has a built-in manpage viewer plugin. So, the first thing to do is to make vim always load that plugin.

In my .vimrc add the following:
Code:
" Manpage plugin
runtime ftplugin/man.vim

The next thing we need to do is to tell our shell to use Vim as a manpager. In my .zshrc (you may use a different shell so make adjustments as necessary) I've added the following:
Code:
MANPAGER="vim -M +MANPAGER -"
export MANPAGER

But when viewing manpages I like using 'q' to quit (like when using more(1) or less(1)). To get that functionality, we change the above to add the mapping 'q' for quit.
Code:
MANPAGER="vim -M +MANPAGER -c 'map q :q<CR>' -"
export MANPAGER

Finally, you can use your own, or adjust a default, colorscheme to view man pages with more/different colors.

What we're going to do now is to set some tamer default colors to a built-in color scheme as a demonstration. In my .vimrc, I add the following (for example) to modify the 'desert' colorscheme:
Code:
augroup my_colorschemes
  au!
  au Colorscheme desert hi Normal ctermbg=NONE
              \ | highlight Special ctermfg=240 cterm=NONE
                \ | highlight Comment ctermfg=245
              \ | highlight Type cterm=NONE
                \ | highlight Normal ctermfg=249
augroup END

And, now in our .zshrc we add the colorscheme to the vim-manpager command.

Code:
MANPAGER="vim -M +MANPAGER -c 'map q :q<CR>' -c 'colorscheme desert' -"
export MANPAGER

Enjoy.
 
Back
Top