Accessing man pages

4
(32)

Did you know you can access man pages from Vim? That’s right, the richly detailed help documentation provided by Unix is available right from with Vim:

  • Press <leader>K on top of any keyword in any file and Vim will open the man page for that program.
  • :Man some_program – Since I don’t often have the names of various Unix utilities written out in my software, using :Man is a bit more practical.

When is this useful? The first can be useful when reading README files, as those sometimes have various executables written out inside of them. I’ve used this on occasion. Do you edit shell scripts often from Vim? Then <leader>K can really come in handy for you.

But :Man has a bit more utility for me. If you’re like me, you try to stay in Vim for as much as of your workflow as possible. When editing text, you might be shelling out from Vim and using normal Unix command line tools, each of which has their documentation in the man pages.

I also like to stay inside of Vim for all my Git operations. Doing so drastically improves my workflow as I avoid context switching back to a terminal. (We wrote a whole course about this!) If I’m ever unsure about a particular Git command, I can access Git’s man pages without leaving Vim. For example:

  • :Man git-log – Show all the various git log options and documentation, without leaving Vim.

To make :Man work, you just need to enable this capability inside your .vimrc with the following line:

runtime ftplugin/man.vim

In the example video below I show you both of these. I happen to have the Ruby package management program bundler mentioned in this README. By pressing \K when on top of bundler, I open the man page for bundler. Next, I check the documentation for git log by running :Man git-log.

How useful was this tip?

Average rating 4 / 5. Vote count: 32

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

92 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

6 thoughts on “Accessing man pages”

  1. Didn’t work for me using current MacVIm n my Mac.
    leader K nor :Man
    K in normal mode seems to work

  2. Well, here is a new one on me, the Leader key … I guess I will have to search this site to find Leader Key ..

  3. Nope, no article on Leader Key but searching the web I see it is ‘\’ by default but I have no idea how it could be useful..
    NOTE: you don’t have to publish my comment, I am just giving you my feedback 😉

    So, why a Leader Key, why do I need it and how could I have been using vi for so many years and never come across it… Weird

Leave a reply

Your email address will not be published. Required fields are marked *