jamesoff.net




6
Mar
2008
3

vim as a man-page reader

Sure, why not :)

This goes in your zshrc:

  vman() {
    if [ $# -eq 0 ]; then
      /usr/bin/man
    else
      if man -w $* >/dev/null 2>/dev/null
      then
        /usr/bin/man $* | col -b | vim -c 'set ft=man nomod' -
      else
        echo No man page for $*
      fi
    fi
  }
  alias man='vman'

And this goes in your vimrc (in a suitable augroup):

  autocmd FileType man setlocal ro nonumber nolist fdm=indent fdn=2 sw=4 foldlevel=2 | nmap q :quit<CR>

Now you’ll get nicely highlighted man pages with folded sections, and you can hit q to quit just like less.

Vim as a manpage viewer


Permalink | Posted in FreeBSD Linux Sysadmin and tagged  

3 comments on “vim as a man-page reader”

  1. Posted by ivucica (Permalink)

    This is sick, perverted, and … I like it :) Although I’m too lazy to actually use it :D


  2. Posted by itai (Permalink)

    Very cool!

    Two comments: A. You might want to use “nmap ” instead of “nmap”. B. This breaks man page autocompletion - instead of being offered man pages, you’re offered files in the current directory (as you would be for vim). Any ideas how to fix this?


  3. Posted by itai (Permalink)

    A solution to the above problem, and also a different approach:

    (a) Inside a directory in your $PATH (say, ~/bin), create a file called ‘_man2vim’, containing the following:

    #!/bin/sh col -b | vim -c ’set ft=man nomod’ -

    Make this file executable.

    (b) Wherever it is you like to add aliases (be it .bashrc, .bash_alises, .zshrc or anything else), add the following alias:

    alias man=’man –pager=_man2vim’

    (c) VoilĂ .



Add a comment