How can I keep the content I was reading from man after I quit?

Solution 1:

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.

   -X or --no-init
          Disables sending the termcap initialization and deinitialization
          strings  to  the  terminal.   This is sometimes desirable if the
          deinitialization string does something unnecessary, like  clear‐
          ing the screen.

Eg PAGER="less -X" man man could be used for testing it out, and if you find this behavior preferable you might consider setting PAGER to this value permanently.

Solution 2:

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.

Solution 3:

As not only less but also other text applications like vim exhibit the same extremely annoying feature, what I do is simply removing the ability for the terminal to support the involved commands from the terminfo database.

These commands are smcup and rmcup, which were designed to allow switching on and of a move where the cup 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 :

    [[ ! -d /tmp/terminfo ]] && { mkdir /tmp/terminfo || return ; }
    cd /tmp/terminfo || return
    TERM=xterm infocmp >
    sed -e 's/rmcup=[^,]*,//'  -e 's/smcup=[^,]*,//' > xterm.src
    if diff xterm.src
      echo xterm terminfo already patched
    TERMINFO=/tmp/terminfo tic xterm.src
    if [ -f /usr/share/lib/terminfo/x/xterm ] ; then
      if [ -f /lib/terminfo/x/xterm ] ; then
        if [ -f /usr/share/terminfo/x/xterm ] ; then
          echo xterm terminfo not found ; return
    if [ ! -f ${XTERM}.org ]
      sudo cp ${XTERM} ${XTERM}.org || return
    cat /tmp/terminfo/x/xterm | sudo dd of=${XTERM}

If your terminal entry doesn't fallback to xterm, you should replace xterm by the right terminal name in the script.

Solution 4:

You can pipe the output to the cat command

man man|cat

or use it instead of the default pager, as in this example which invoke man on itself:

PAGER=cat man man