Home » Questions » Computers [ Ask a new question ]

'less' command clearing screen upon exit - how to switch it off?

'less' command clearing screen upon exit - how to switch it off?

How to force the less program to not clear the screen upon exit?

Asked by: Guest | Views: 25
Total answers/comments: 2
Guest [Entry]

"To prevent less from clearing the screen upon exit, use -X.

From the manpage:

-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 clearing
the screen.

As to less exiting if the content fits on one screen, that's option -F:

-F or --quit-if-one-screen

Causes less to automatically exit if the entire file can be
displayed on the first screen.

-F is not the default though, so it's likely preset somewhere for you. Check the env var LESS."
Guest [Entry]

"Or just set it in your global git config:

git config --global core.pager 'less -FX'

This way other tools are unaffected (which I like)."