Vim Tips Wiki

Tlgrok/Use vim as a man pager

< User:Tlgrok

Revision as of 18:38, May 6, 2009 by Tlgrok (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
1,616pages on
this wiki

This is a draft, quarantined as a subpage of my own userpage until (and if) it is ready to face the world. Feel free to edit it.

Vim as a man pager for &#039;find&#039; command

Man page of 'find', as displayed by Vim.

man is a standard Unix and Linux command to view the manual page for given command. Man page can be viewed using Vim in two ways: through a function called from within Vim, and as a pager given to the man command itself. There are several advantages to using Vim to view man pages: the page will be colored, you could fold by indentation, you could jump to man pages mentioned in the text using tags (<Ctrl-]>), and you'll have all of Vim's search capabilities at your fingertips.

Viewing man pages from within VimEdit

To view man pages from within Vim, you need to load the man.vim plugin, found in $VIMRUNTIME/ftplugin. You can do this by adding the following to your .vimrc:

  runtime ftplugin/man.vim

Once this is done, you can load a man page simply by typing (in insert mode):

  :Man <command>


  :Man find

Using Vim as a man pagerEdit

For this to work, you need to create a script inside a directory in your $PATH, and make it executable. We'll call this script _man2vim. These should be its contents:

  col -b | vim -c 'set ft=man nomod' -

Now, wherever it is you add aliases (.basrc, .zshrc, or anywhere else), add the following alias:

  alias man='man --pager=_man2vim'

You can now view a man page using Vim by typing (in the shell) the following:

  man <command>


  man find

The man filetypeEdit

Vim recognizes a man filetype. Thus, if you'd like to be able to exit a man page simply by pressing q, you can add the following to your .vimrc:

  autocmd FileType man nnoremap <buffer> q :quit

External linksEdit

Around Wikia's network

Random Wiki