man Command – How to Open Multiple Man Pages in less

lessman

I've noticed that when running man command1 command2, the behavior is: first the man page for command1 is formatted and displayed in less, and then after that less instance exits (e.g. by pressing q), the man page for command2 is formatted and displayed in a new instance of less.

How can I get multiple man pages displayed within the same instance of less?

less has many features only applicable when multiple files are open, such as multi-file search, cross-file "marks" for positions, and others.

Best Answer

Okay, I've worked out the answer:

mman() { LESSOPEN='|man %s' less -is "$@"; }

After running this function definition, running, for example:

mman postfix postqueue postsuper

will open all three man pages in the less pager, each as separate files, accessible with :n and :p and cross-file searching, etc.


If you wish to read up on how this works, I suggest LESS='+/^INPUT PREPROCESSOR' man less as a good place to start. :)