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.

  • 2
    If you use Vim's manpage support, then you get the whole tabs/windows/kitchen sink feature set as well. – muru Oct 6 '17 at 5:47
  • @muru, interesting. With the approach at that linked page, I get Error detected while processing command line: E492: Not an editor command: MANPAGER, but :help :Man within Vim shows how to enable the :Man command—not quite the same, though.... – Wildcard Oct 6 '17 at 5:58
  • the page says "To start using the ":Man" command before any manual page was loaded, source this script from your startup vimrc file: runtime ftplugin/man.vim" O.o – muru Oct 6 '17 at 6:00
  • 1
    Before 7.4.1804, to use Vim as manpager you would have needed a plugin or some custom setup. The MANPAGER command was added to make it possible to use Vim without plugins as the manpager. – muru Oct 6 '17 at 6:28
  • 1
    @Wildcard The manual is wrong (or ftplugin/man.vim is broken, if you prefer). The :Man command exists only if the current filetype is man. So load ftplugin/man.vim and run :setf man: then you'll be able to use :Man. That said, perhaps you shouldn't admit in polite conversation that you're still running Vim 7.2 at the end of 2017. :) – Satō Katsura Oct 6 '17 at 7:11

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. :)

  • That's a nice approach. If you have man-db >= 2.5.0, then you can add MAN_KEEP_FORMATTING=1 to the internal man invocation, and that way you won't lose the usual manual page bold/italic formatting. – Colin Watson Nov 22 '17 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.