Skip to content Skip to sidebar Skip to footer

How To Not Overwrite Previous Terminal Contents

I'm not sure if this is a duplicate, but I have no clue what to search for if it is, as I don't know the name for this phenomenon. Basically, whenever I use vim and less on certain

Solution 1:

The behavior being described is the xterm-style alternate screen. There are two cases:

  • when it is used, the terminal switches to the alternate screen when you run full-screen programs such as vim.
  • when not used, the terminal continues in the normal screen when running full-screen programs.

The normal/alternate screens are the same size: the visible portion of the terminal ignoring the scrollback area. You can see the scrollback using a mouse. If you do that while switched to the alternate screen, you can see the scrollback adjacent to the current (alternate) screen. After switching back, e.g., when vim exits, the previous lines are shown throughout the scrollback and current (normal) screen. There is no marker between the two.

Some aspects of the normal/alternate screen were recently discussed in What mechanism allows ViM to temporarily overwrite the entire console?

Most applications on Unix (and Linux and BSD and ...) pay attention to the TERM environment variable, which they (or a library such as ncurses) uses to retrieve information from the terminal database. In principle, one can set TERM separately for different applications to elicit different behavior (with the caveat that some applications such as vim have built-in tables to "fix" the terminal database which they may apply without warning). For example, running in a POSIX shell (or something like bash), you could type this to run vim and less with two different terminal descriptions:

TERM=vt100 vim foo.c
TERM=xterm less foo.c

Post a Comment for "How To Not Overwrite Previous Terminal Contents"