Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

see the example below to understand my problem ; consider my console prompt look like this

user@server $ ls
"I opened a file temp"
user@server $ vi temp

"temp will open in the same window, when I close temp, I dont come back to "

user@server $ ls
user@server $ vi temp
user@server $

instead I come back to something like this

user@server $ ls
user@server $ vi temp
"temp file content"
"temp file content"
"temp file content"
user@server $

Its eating up my visible screen space, and I may end up losing some important output because of this file content.

share|improve this question
2  
If it's "important output" it shouldn't be in your scroll-back: it should be in a file. Cut and paste it, or pipe/tee it there in the first place. –  ams Apr 25 '12 at 12:42

3 Answers 3

There is a feature in terminals called "alternate screen". It lets a program use a different virtual "screen" and restore the previous one when it exits.

You need a terminal emulator that supports this feature. Gnome-terminal, urxvt, and xterm all do. I've never seen it disabled by default, but if it is just disabled, you may be able to enable it using Xresources. If you have xterm or urxvt, then in your ~/.Xresources or ~/.Xdefaults file, add the following:

For xterm:

XTerm*titeInhibit: false

For urxvt:

urxvt*secondaryScreen: true

Some gui terminals may have an options panel with a check-box for enabling the alternate screen.

More resources:

http://blogmal.42.org/tidbits/titeinhibit.story

http://shallowsky.com/linux/noaltscreen.html

share|improve this answer

Try using screen (or byobu, which is an extended version of screen you might like better). It needs no special terminal support beyond the standard features.

You launch it like this:

screen

or

byobu

Easy!

Then it opens with a new shell. Once inside, you can open a second shell at the same time by pressing Ctrl-Ac, and then you can switch between then with Ctrl-A1 and Ctrl-A2. You can repeat this to open even more at once.

You can also open vim (or anything else) in another view like this (from within one of the existing screen views):

screen vim blah

As an added bonus you can close the terminal (not exit the shell), log out, and when you next log in again (assuming the machine hasn't been rebooted) you can reconnect to your old session, and everything will still be as you left it:

screen -r

The downside is that you can't use the terminal's own scroll feature - you have to use screen's scroll feature: hit Ctrl-AEsc, then you can page up and down, and return to normal mode with Esc.

share|improve this answer

Use the full blown vim version, not the vim-tiny one. Both vim and vim-tiny are conveniently called from the command line using vi as it is a drop in replacement for the original editor. Many distributions come standard with vim-tiny.

share|improve this answer
    
I downvoted this answer because it's technically incorrect. The OP also stated they were using vi not vim. If you make an effort to correct, or at least clarify and expand, your answer, I'll remove my downvote. –  uther Apr 25 '12 at 18:37
    
vim is called with vi from the command line. Many distributions, including Ubuntu, have vim-tiny installed by default which again is simply called from the command line by typing vi. One of the habits of vim-tiny is the effect as described above. –  jippie Apr 25 '12 at 18:45
    
Then perhaps you should include that information in your answer and help the OP understand what package they may have installed (perform which vi and/or rpm -qa | grep vi) and the behavior that can be expected. –  uther Apr 25 '12 at 18:49
    
Not all distributions use RPM package manager, so that is useless information as long as we don't know the distribution. –  jippie Apr 25 '12 at 18:55
    
True. I was just providing an example of what might be useful to help the OP. –  uther Apr 25 '12 at 18:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.