So we use man whatever
to get usage and other info regarding the whatever
command, when the relevant section of info is found, I'd like to quit the man
command with the info left on screen. So I can type the next command with the referee above. But the man
command quits the whole screen to recover the old screen similar to vim
.
Is there a way to achieve this?
I believe this is not so much about
man
itself but rather about your pager of choice (PAGER
environment variable) combined with the terminal in use.I'm guessing your pager is probably
less
(typical default pager nowadays and fits with the description).less
has an option-X
that may get you a behavior along the lines of what you're looking for.Eg
PAGER="less -X" man man
could be used for testing it out, and if you find this behavior preferable you might consider settingPAGER
to this value permanently.If you are running less as your pager (which is very common), you don't need to deal with modifying your pager, just do I/O redirection:
man <whatever you want to man> | cat -
This will print a copy to the terminal so you can scroll up when you need it.
As not only
less
but also other text applications likevim
exhibit the same extremely annoying feature, what I do is simply removing the ability for the terminal to support the involved commands from theterminfo
database.These commands are
smcup
andrmcup
, which were designed to allow switching on and of a move where thecup
command (cursor position) was allowed.Here is a shell function I used to automatize the task, it works at least with Solaris and likely most Linux distributions :
If your terminal entry doesn't fallback to
xterm
, you should replacexterm
by the right terminal name in the script.You can pipe the output to the
cat
commandor use it instead of the default pager, as in this example which invoke man on itself:
Without modifying the pager, a solution with pipes that can work in most of the environments:
Examples for
man ls
man ls | cat
man ls | more
man ls | grep somestring
it's 2016, just open a second terminal or tab or window or read the man online ..
Even on my servers (FreeBSD) I install X and xfce. Then I allocate a big buffer (e.g. 10 000 lines) for the terminal emulators so that I can fully scroll out the man page in one of them, and use a separate terminal instance to assemble the command. Works a treat.