What is a way to read man pages in vim without using temporary files

MYV picture MYV · May 24, 2013 · Viewed 14.4k times · Source

I want to be able to read man pages in vim. For some reason, it seems that vim isn't able to read the output of programs through piping (i.e '(man ls) | vi' doesn't seem to work, bonus points to somebody who can explain why), and to get around this, I've been using the following little script:

tempo = `mktemp`
man $1 > $tempo ; vi $tempo

This script uses temporary files which I guess works fine, but I was wondering if there was a good way to read man pages in vim without resorting to making temporary files

Answer

glts picture glts · May 25, 2013

Vim includes a man page viewer, :Man, in its runtime files.

Put this line in your vimrc:

runtime! ftplugin/man.vim

Now you can read syntax-highlighted man pages inside Vim by running :Man. For example:

:Man 3 printf

Even better, you can just place your cursor on a word in the buffer and press <Leader>K (\K) to see the man page for that word.

See :h find-manpage for complete usage and installation instructions.