Viewing man pages in vim
Try this: capture the man output, and if successful launch vim
viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man" - ; }
I like the idea of checking the man
return code; you can't pipe to the test, though. You could just run man
twice:
viman () { man "$@" >/dev/null 2>&1 && man "$@" | vim -R +":set ft=man" - ; }
This runs man ... | vim ...
only if the first invocation of man
was successful.
There's an environment variable called MANPAGER
which can be used to make man
call the command you want for displaying the manpage. The advantage of this is that you call man
directly, and it won't run the pager at all if the manpage didn't exist.
So a wrapper script, say in ~/bin/vimman
:
#! /bin/sh
vim -R +":set ft=man" -
With this in your shell initialisation files somewhere:
export MANPAGER="$HOME/bin/vimman"
And you can directly run man foo
to manpages in Vim.
(Depending on the man
command being used, you could also have:
export MANPAGER='vim -R +":set ft=man" -'
directly instead of a wrapper script.)
If you have a new enough Vim, you can use the --not-a-term
option to stop Vim from complaining about stdin not being a TTY.
Shameless plug: I wrote a small plugin to facilitate using Vim as manpager.