[Linux] Vim as (Man)Pager

Those who know me, also know, that I love vim(1). Vim is the editor for any system. It works great on Linux, Windows, OS X, …. And there’s a GUI version of it (gVim), as well as a CLI version.

Yesterday I made a new discovery, while installing vim on a fresh installation of Gentoo. In portage there’s a vim-pager USE flag. It caught my attention, I googled a bit, and soon I found out: vim can be used as a pager application!

Pager application? Yes, thos are the little apps, like more(1) or less(1) (there are many other less known pagers like pg(1) (part of the util-linux-ng package, so you should find it on every Linux out there) or most(1)). They where invented to handle large amount of data, mostly in data streams. E.g if you’d use

pygospa@telperion ~ $ cat /dev/urandom

then you’d get a neverending data stream that flys through your screen. If you’d now actually want to see what’s flying through there, you’d use a pager, like this:

pygospa@telperion ~ $ cat /dev/urandom | more

And as you can see, now the monitor stays and shows you just a monitor-full of information (called a page). If you’re ready reading, just tab space, to get the next page, and so on (okey, okey, that’s propably the most stupid example there is. Propably you’d like to use this when you view something such as dmesg).

Now, vim has a pager application, too. And a pretty cool one. Why? Well, for once it uses colors, which is pretty cool. Try it out with any configuration file, you have, and just watch the difference, e.g.:

pygospa@telperion ~ $ cat ~/.bashrc | more
pygospa@telperion ~ $ cat ~/.bashrc | vimpager

But of course, that’s not all. You’ll be able to scroll through the text like you’re used to in vim (using hjkl), you can use searches and regular expressions, like in vim, it’ll show you all the information like it does in vim (exact position of the cursor, percentage of text, where a opening bracket is closed and vice versa), etc. I haven’t figured out all the features yet, but let me tell you: It just makes paging more fun!

And best of all: You can even use it to view your man pages. I guess for any other linux distribution there’s a seperate package (e.g. vimpager), or the feature is allready installed. If you’re using Gentoo, you’d need to activate the proper use flag.

telperion pygospa # emerge -av vim

These are the packages that would be merged, in order:
[ebuild   R   ] app-editors/vim-7.2.182  USE="acl bash-completion cscope gpm nls perl python ruby vim-pager -minimal -vim-with-x" 0 kB

Best practice is to edit your /etc/portage/package.use. Just add following line into the file:

app-editors/vim vim-pager

And there you go.

To use vimpager as default pager application (besides just calling it), on Gentoo you’d have following options:

pygospa@telperion ~ $ export PAGER="/usr/bin/vimpager"

This’ll just change the pager for this sole session. The next time you’ll logon it’ll be back to the old default.

pygospa@telperion ~ $ echo 'export PAGER="/usr/bin/vimpager"' >> ~/.bashrc


pygospa@telperion ~ $ echo 'export PAGER="/usr/bin/vimpager"' >> ~/.bash_profile

This’ll change it lastingly for the individual user. To change it globaly for all users, you’d edit the PAGER variable in /etc/env.d/00basic.

And to change the man page pager as well you’d have to change following lines in the /etc/man.conf

PAGER          /usr/bin/less -is
BROWSER        /usr/bin/less -is


PAGER          /usr/bin/vimmanpager
BROWSER        /usr/bin/vimmanpager

UPDATE: See the comments for a much better approach on this one!

Of course that’s a global change again. You could rewrite the variable localy or just for a session as you did with the PAGER variable.

And don’t forget to call

telperion pygospa # env-update && source /etc/profile

to set the new environment variables and refresh your profile.


4 thoughts on “[Linux] Vim as (Man)Pager

  1. Pingback: Before building a Kernel « ~ PygoscelisPapua ~

  2. It’s not one of the best ideas to edit configs in /etc/* if you have other options. (files get updated in subsequent updates and then you’ve to check things while doing etc-update!). The easy way of setting man pager is to set env variable

    either in your .bashrc or systemwide in /etc/env.d/

    I prefer using a personalized file /etc/env.d/99personal

Please comment. I really enjoy your thoughts!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s