Wikia

Vim Tips Wiki

Tlgrok/Use vim as a man pager

Talk0
1,610pages on
this wiki

< User:Tlgrok

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 'find' command
Man page of 'find', as displayed by Vim.
TlgrokAdded by Tlgrok

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>

E.g.,

  :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>

E.g.,

  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