Whenever I use a pager like less
or an editor like nano
in the shell (my shell is GNU bash), I see a behaviour I cannot explain completely and which differs to the behaviour I can observe with other tools like cat
or ls
. I would like to ask how this behaviour comes about.
The —not easy to explain— behaviour is that normally all output to stdout/stderr ends up being recorded in the terminal-emulators backbuffer, so I can scroll back, while (not so normally to me) in the case of using less
or nano
, output is displayed by the terminal-emulator, yet upon exiting the programs, the content "magically disappears".
I would like to give those two examples:
seq 1 200
(produces 200 lines in the backbuffer)seq 1 200 | less
(lets me page 200 lines, yet eventually "cleans up" and nothing is recorded in the backbuffer)
My suspicion is that some sort of escape codes are in play and I would appreciate someone pointing my to an explanation of this observed behavioural differences.
Since some comments and answers are phrased, as if it was my desire to change the behaviour, this "would be nice to know", but indeed the desired answer should be the description of the mechanism, not as much the ways to change it.
man
orvi
command, I can no longer see what was on the screen. Thanks for asking this question that has bothered me! I hate doing aman vi | more
! – Mark Stewart Jan 11 '17 at 19:56LESS=X man vi
andvim "+:se t_ti= t_te="
(sorry, doesn't work onvi
) for the behaviour you want. The first works becauseman
typically usesless
and-X
causesless
to not initiate the terminal's secondary screen. The second works by tellingvim
that the terminal escape sequences to initiate and end secondary screen are the empty string. – JoL Jan 12 '17 at 00:31