This is actually a function of the terminal emulator you are using (xterm, gnome-terminal, konsole, screen). An alternate screen, or altscreen, gets launched when programs such as less
or vim
are invoked. This altscreen has no history buffer and exits immediately when you quit the program, switching back to the original screen which restores the previous window content history and placement.
You can prevent less
from launch in an altscreen by passing the argument "-X".
less -X /path/to/some/file
You can also pass "-X" as an environment variable. So if you are using bash
, place this in ~/.bashrc
:
export LESS="-X"
However, this disbles the termcap (terminal capability) initialization and deinitialization, so other views when you use less
may appear off.
Another option would be to use screen
and set the option altscreen off
in your ~/.screenrc
. less
will not clear the screen and should preserve color formatting. Presumably tmux
will have the same option.
This blog entry describes the problem and offers some different solutions specific to gnome-terminal
with varying success.
git diff
orgit log
) inless -X
will take up the scroll buffer in my terminal and evict much of the previous output. I'd love it ifless
could just exit with the last screenful of output at the time of the exit; i.e. no more than one page of the scroll buffer would be taken after quittingless
. Any ideas?-R
is usually a safer choice than-r
.-R is "Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained correctly in most cases."
-c
is about how to update the screen when you move around insideless
.