How to change your manpaging utility in Linux/Unix


When opening manpages with man on a Linux/Unix system, the manpage is printed and fed into a line viewer such as less (1). However, the utility used to open and view manpages can be easily changed by exporting the $MANPAGER environment variable to something else. Other possible utilities include batcat, vim, and even gedit or Firefox just for fun.

(NOTE: do not use gedit or Firefox as your primary manpager.)

Setting the $MANPAGER variable

When a manpage is opened using man, it is converted to a readable format and sent to the manpager via stdin. The $MANPAGER variable defines where the manpage is sent (by default, it is piped to less). It should contain a shell command that takes input from stdin and does something with it.

The following examples are some useful or interesting ways to use this functionality. Some are original, some aren't. To set one of these as your default manpager, you can copy the line to your shell's init file (e.g: .bashrc, .zshrc)

# use batcat as manpager
export MANPAGER="sh -c 'col -bx | batcat -l man -p'"

# use vim as manpager
# I found this one in distrotube's .zshrc. link
export MANPAGER='/bin/bash -c "vim -MRn -c \"set buftype=nofile showtabline=0 ft=man ts=8 nomod nolist norelativenumber nonu noma\" -c \"normal L\" -c \"nmap q :qa<CR>\"</dev/tty <(col -b)"'

# gedit
export MANPAGER="sh -c 'col -bx | gedit -s -'"

# firefox
export MANPAGER="sh -c 'col -bx > /tmp/manpage; firefox -new-tab /tmp/manpage; rm -rf /tmp/manpage'"

# zenity
export MANPAGER="sh -c 'col -bx | xargs -0 -I \"%\" | zenity --info --window-icon=\"question\" --width=700 --height=900 --text=\"%\"'"

# print manpages to stdout
export MANPAGER="cat"

# read messages using text-to-speech
export MANPAGER="sh -c 'col -bx | espeak'"

# print manpages in rainbow
export MANPAGER="sh -c 'col -bx | lolcat'"

Homepage Posts