Some time ago I was looking for some advice on StackOverflow, and one thing caught my eye: someone provided a shell command which apparently started man
already showing some section. It is very simple, but still nice. It turns out that less
supports (among many others) the environment variable LESS
, which contains just commands you’d normally type in less
. Since one of the less
commands is searching, you can use it to invoke less
(and hence also man
, which uses less
as the default pager) at the first occurrence of any string you want. For instance, here is how to open the manpage of less
itself on the description of the environment variables influencing its behavior:
LESS=+/'ENVIRONMENT VARIABLES' man less
I am not sure how useful this is, but it is definitely cool, so I just had to share it. By the way, very similar behavior can be emulated in Emacs (obviously!), in both its manpage viewers, with the Man-goto-section
command (bound to the g
key by default). Needless to say, viewing manpages in Emacs gives a superior user exprience than using less
in a terminal – all Emacs goodies (with the addition of your customizations, of course, like Avy or Swiper) are available, plus (Wo)Man-specific commands (press C-h m
in either Man or WoMan mode to see them).