I often work in vi, suspend vi, run something on the cli, and then fg back into vi to work on the results. For instance, fixing errors that showed up when I ran the cli command.
However, when I fg vi, vi "wipes" the current terminal buffer and I can't see the "last screenful" of terminal output in the scrollback buffer.
Is there some setting in vi (or screen, I use screen) which would help me here?
I have searched google for a long time with no answers. I also realize that there are other workflows that solve this problem, but they aren't perfect (run from inside vi means no shell completion, etc).
I don't know if this will help but: I use a mac these days, but I used to use NetBSD and Linux at uni. It always bugged me that programs like
less
,man
,vi
, etc. would clear the screen when they exited. I could switch it off inless
with the-X
option, but that wasn't an option (literally) with the others.I found a config setting in
xterm
that solved the problem for me. I'm afraid I don't remember the option; it was available through one of the menus and I think through the-xrw
commandline option.Obviously this can only be helpful if you use
xterm
.Changing your terminal type to ansi could work:
But I'm sure there are some negative side effects.
In answer to your question in your comment on this answer: it seems to actually be the
t_ti
variable. In your~/.vimrc
add a line that says:You can try it out first from within
vim
by entering that command at the:
prompt.This is not a solution, but a nice workaround, that I've just started using. Create the following wrapper script for vi (I placed it in my ~/bin/vim-wrapper) and possibly alias it with something like:
Content of
vim-wrapper
(see this answer for details):This will solve completely the screen wiped out issue. Unfortunately, it does not solve the have to scroll up quite a lot when you edit a long file in vim. But if you set a large enough buffer in your xterm-like (I use gnome terminal 2.22.1) you'd be ok.
If you're using
screen
, then surely it would make sense to do your editing in one window, and your compiles in the other, and then just use the^A[n]
sequences to flip between your terminal output and code screens?I'm not 100% sure whether this will help you or not, but vim tries to restore the screen it found when it was started. I like that behavior and spent quite a bit of time to "repair" a vim installation on a machine where this didn't work.
I had to set the t_ti and t_te variables. My hunch is that you should unset t_te.