When I work in terminal, I see the history of the last shell commands execution output. If I run vim, I see the file I open full screen. When I exit vim, I can see the history of the last shell commands again.
However, when I use vim from screen. I see the footprint of the file I was just editing on my exit from vim instead of the history of the last shell commands. I'd like to see the shell's history though.
How can I achieve this behaviour?
I used:
- terminal.app and iterm2.app
- tried switching xterm to xterm-256color (in iterm2.app)
- checking and unchecking "Save lines to scrollback when an app status bar is present" and "Save lines to scrollback in alternate screen mode" (in iterm2)
- adding termcapinfo xterm ti@:te@ to .screenrc (although it should be a solution to the opposite problem, but why not to try)
- sshing to linux machines and trying to use gnu-screen there
Up to now I didn't get the desired behaviour.
P.S.
I googled a bit and saw comments of people who try to solve the opposite problem:
The main idea behind this behaviour is whether programs use alternate screen to save a picture of the shell history and show it when vim exits. Thus if one wants to solve the opposite problem, he should
UPDATE : I had forgotten about a feature of
screen
that disables alternate screen support by default.Add
altscreen on
to your$HOME/.screenrc
to enable it. This is probably all you have to do; all the messing about with$TERM
,$TERMCAP
, and$TERMINFO
is probably unnecessary. I'll leave the rest of this answer here anyway.I've had this in my own
.screenrc
so long it slipped my mind.To enable this feature for the current session, type your
screen
escape character (Cntrl-A by default) followed by:altscreen on
Enter.Without this,
screen
won't respond to the escape sequences, even if they're defined in terminfo or termcap.vim
(andless
, and most other curses-based full-screen programs) use thesmcup
andrmcup
strings defined by the terminfo entry for your terminal. (These are referred to asti
andte
, respectively, in the older termcap system).smcup
switches to the alternate screen, andrmcup
switches back to the primary screen.If your terminfo entry doesn't have these strings, programs won't be able to do that.
The screen command, by default, sets your
$TERM
to"screen"
. Apparently the "screen" terminfo entry doesn't havesmcup
andrmcup
.If you feel like hacking terminfo entries, you can modify your existing information for "screen" to add
smcup
andrmcup
. You'll need theinfocmp
command to convert your terminfo to a text, andtic
to convert it back to the binary form used by terminfo.A simpler solution is to set your
$TERM
environment variable to whatever it was before you invoked thescreen
command. Almost all terminal emulators these days are based on the old DEC VT100, so they should be sufficiently compatible.On my system, for example, when I login I have
TERM=xterm
; it's likely something else on MacOS. Within ascreen
session, by default, I'd have:I could change it to
xterm
like this:(Again, replace "xterm" by whatever
$TERM
is on your system.)You can also add
to your
$HOME/.screenrc
. In factscreen
has a number of options for tweaking your termcap/terminfo settings;man screen
and search for "terminfo" for the gory details.