When I run less on some file, the prompt goes away, and I get the contents of the file on screen. Then when I press q, it goes back to the prompt. I think less does this by saving the current terminal buffer, opening a new buffer, outputting the file into the new one, then when closed, discarding the new buffer, and restoring the old, but I don't know what this process is called or how it does this.
I looked in man less but didn't find anything. I tried googling it, but couldn't find anything useful, except that the screen command can do the same thing with shell sessions.
Ultimately, I'm asking because I want git diff to use a new buffer instead of printing inline. I've already set GIT_PAGER=less and git --paginate diff, but they didn't change anything. And I have a workaround, but it's a bit long: git diff --color=always | less -R
Update: After some research, it looks like tput smcup and tput rmcup are high-level commands to do the same thing, probably using the termcap package.
less's-Xoption which disables this behaviour. Btwman lesshelps: “Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals.” – dessert Dec 07 '17 at 21:19lesssettings? (Look at theLESSvariable in particular.) On my system,gitpages by default, usingless; but if you have-X,-Eor-Fin yourlessconfiguration it could give the impression that it’s not initialising the terminal at all. – Stephen Kitt Dec 07 '17 at 22:06$LESSis unset. To clarify,gituseslesson my system, but doesn't initialize a new terminal. I've tried setting git's pager asless -+Xin the gitconfig and$GIT_PAGER, but neither worked. – wjandrea Dec 07 '17 at 22:26TERMset to? – Stephen Kitt Dec 07 '17 at 22:28