Manpages 彩色化又一法

{ 撰文/shaohao }

在 LinuxTOY 上面确实能找到不少好东西。前段时间想把 Manpages 彩色化,LinuxTOY 一找,还真有,彩色版本的 Manpages,当然还有用 most 工具的。 不过我发现了另一种 Manpages 彩色化解决方案,用——Vim,主要是看中它的快速跳转功能。

把下面的代码加入到 ~/.bashrc 里面:

# Use VIm as man pager
vman () {
    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>' -\""

    # invoke man page
    man $1

    # we muse unset the PAGER, so regular man pager is used afterwards
    unset PAGER
}

然后用 vman 就能看彩色版的 Manpage 了,当然了,你依然能用 man 看黑白版本。

最绝的是,用 Vim 的解决方案,当你在 Manpage 中看到 See Also 关键字后,你可以使用“Ctrl+]”快速跳转到 See Also 提供的参考指令中。 例如:

vman grep

然后转到最后,光标指到 See Also 提供的 xargs(1) 参考指令上,然后“Ctrl+]“就能立刻查看 xargs 的 Man 文档了。 (P.S. 但是不知道怎么跳回去-_-)

{ Thanks shaohao. }

Read More:

14 Comments

  1. 1 Grissiom Commented @ 2010-01-24 10:24Reply to this comment

    Ctrl+t 跳回 ;)

  2. 2 xhh Commented @ 2010-01-24 10:49Reply to this comment

    或者 Ctrl+o 后退 (Ctrl+i 前进)

  3. 3 mousecat Commented @ 2010-01-24 11:41Reply to this comment

    good!

    but no word wrap tho....

  4. 4 mousecat Commented @ 2010-01-24 11:47Reply to this comment

    I lie-d....it does word wrap....

  5. 5 lilydjwg Commented @ 2010-01-24 16:17Reply to this comment

    回去是 Ctrl-T。 这样太麻烦,看我的: vman () { vim +"set ft=man" +"Man $*" }

  6. 6 ccaaatt Commented @ 2010-01-24 16:23Reply to this comment

    我现在宁可用dwww或者man2html

  7. 7 Iven Commented @ 2010-01-24 16:54Reply to this comment

    Vim 自带彩色 Manpages 支持吧…… :runtime ftplugin/Man.vim :Man grep 或者在函数名上面按,k 就可以了。

  8. 8 billkof Commented @ 2010-01-24 17:04Reply to this comment

    Man.vim 哪里下载?

  9. 9 Iven Commented @ 2010-01-24 17:33Reply to this comment

    @billkof: 自带的……

  10. 10 fanhe Commented @ 2010-01-24 18:23Reply to this comment

    vman 了一下 mplayer,发现有8K5行,太恐怖了

  11. 11 tocer Commented @ 2010-01-27 9:06Reply to this comment

    色彩还是不如原来的的多。

  12. 12 tanke Commented @ 2010-01-27 16:46Reply to this comment

    使用Ctrl-t可以跳回去,需要在~/.vimrc文件中增加设置“set hidden #没有保存的缓冲区可以自动被隐藏“,但在普通vi编辑多个文件时需注意使用":qw!"退出时可能对未保存的隐藏缓冲区造成丢失,注意! 另,”man $1“需修改成”man $*“,用于多参数命令,如”man 3 printf“

  13. 13 Ray Commented @ 2010-02-20 9:21Reply to this comment

    vim 的 manpages 插件

  14. 14 lk Commented @ 2010-03-16 12:09Reply to this comment

    怎么跳转时提示: E433: 没有 tag 文件 E426: 找不到 tag: zgrep