问题
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).
回答1:
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?
回答2:
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.
回答3:
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:
set t_ti=""
You can try it out first from within vim
by entering that command at the :
prompt.
回答4:
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 in less
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
.
回答5:
Changing your terminal type to ansi could work:
:set term=ansi
But I'm sure there are some negative side effects.
回答6:
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:
alias vi='~/bin/vim-wrapper'
Content of vim-wrapper
(see this answer for details):
#!/bin/bash
LINES=$(tput lines)
for i in `seq 1 $LINES`; do
echo $i
done
vim $@
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.
回答7:
It is possible that scrolling the screen Ctrl+E or Ctrl+Y might do the trick as well.
来源:https://stackoverflow.com/questions/630519/can-you-make-vi-advance-the-screen-when-opened