What is a way to read man pages in vim without using temporary files
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.
For some reason, it seems that vim isn't able to read the output of programs through piping […]
According to the man-page, you need to specify a file of -
to get it to read from standard input; so:
man ls | vi -
If that doesn't work, you might try using process substitution:
vi <(man $1)
which creates a sort of pseudo-file and passes it to vi
.
Here is what I did: I've made a function in my .bashrc:
vman() { vim <(man $1); }
When I call vman
this automatically calls Vim showing the man page. It works great.
On my system (Mac OS X), I found that the above left control characters in the output. Instead I used:
export MANPAGER="col -b | vim -MR - "
then just e.g.
man vim
The vim options turn off modifying the buffer and make it read-only. This stops vim complaining if you try to exit with ":q" (you can use :q! of course, but you might as well set the options).
This is also handy for general use - I have the following. The -c command names the buffer, just for completeness.
alias vimpager="vim -MR -c 'file [stdin]' -"