Accessing man pages
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 variousgit 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
.
Hi,
:Man didn’t work here (Vim 8.2). Looks like a plugin, no?
Try adding this to your .vimrc (my mistake, sorry!):
runtime ftplugin/man.vim
Didn’t work for me using current MacVIm n my Mac.
leader K nor :Man
K in normal mode seems to work
You are right, my bad! You need this in your .vimrc:
runtime ftplugin/man.vim
I updated the post, thank you!
Well, here is a new one on me, the Leader key … I guess I will have to search this site to find Leader Key ..
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