Vim as Man page viewer

Linux man pages are gold, and much quicker than googling, but I hate having to learn yet another interface for what is just a text flatfile that’s a bit to big to fit on a single 80 x 24 character screen – I want to be able to “/pattern” to find what I’m looking for. While I’m at it, I may as well set my default pager to be vim across the board, not just for help files….. Less is good, more is better, but Vim is the vimmiest.

So, to set your default pager ($PAGER), the program your shell uses for viewing data that’s too big to fit on a single screen, to Vim, do the following:

Add to your .bashrc (/home/yourusername/.bashrc)

export PAGER="/bin/sh -c \"unset PAGER;col -b -x | \
    vim -R -c 'set ft=man nomod nolist' -c 'map q :q<CR>' \
    -c 'map <SPACE> <C-D>' -c 'map b <C-U>' \
    -c 'nmap K :Man <C-R>=expand(\\\"<cword>\\\")<CR><CR>' -\""

That will call Vim. Inside Vim, there may be another override to use a different pager, so we need to clear that by adding to your .vimrc (/home/yourusername/.vimrc)

let $PAGER=''

Reload your .bashrc

 $ source ~/.bashrc

And you’re good to go!

Codemonkey of Node.js, Django, PHP and all things HTML5 Solving tech challenges, one bit at a time.

Posted in bash, linux, vim Tagged with: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *