Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

10.3: Prevent Terminal from clearing screen after commands UNIX
With the new Terminal, certain UNIX commands (vi, less, man, etc.) cause the window to clear when they're done. I personally found this annoying. I typically do a man or a less, then want to copy/paste some info, such as command line parameters, into the same window. One particularly frustrating behavior occurs if you do an less -F on a tiny file. In this case, less exits if the entire file fits on the screen ... but then the screen clears. D'oh!!

Fortunately, this behaviour can actually be defeated quite easily! Simply edit your Terminal -> Preferences and change "Declare Terminal Type ($TERM) as:" to "vt100" and close the window. Only new Terminal windows will pick this up.

Both Apple's supplied /bin/ls and emacs syntax colorized highlighting work great with vt100 and color. And no annoying (well to me anyway) clear-screens at the end of a command! One caveat is that if you use GNU's ls, you MAY have to change the .dircolorsrc in your home directory. Most vt100 terminals do not support color, so you need to tell GNU ls that yours does. Simply add the following line:
TERM vt100
And you're set!

[robg adds: Thank you! That was so annoying I had taken to opening two windows, one with man and the other with what I was actually working on. I figured it was probably a simple fix, I just didn't think it would be THAT simple!]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[13,912 views]  

10.3: Prevent Terminal from clearing screen after commands | 31 comments | Create New Account
Click here to return to the '10.3: Prevent Terminal from clearing screen after commands' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
10.3: Prevent Terminal from clearing screen after commands
Authored by: sharumpe on Wed, Nov 5 2003 at 11:33AM PST
I'm not sure what the steps are to re-enable color when you set TERM=vt100, but if you set TERM=ansi instead, you still get color with no other changes.

Mr. Sharumpe

[ Reply to This | # ]
that's great! try this too
Authored by: SOX on Wed, Nov 5 2003 at 12:27PM PST
yep ansi works well.
I also aliased my ls command in my .cshrc file
alias ls "ls -G"
this colorizes the output without having to set up any color configuration files or scripts

[ Reply to This | # ]
use screen
Authored by: iobuffa on Wed, Nov 5 2003 at 12:04PM PST
This is where screen comes in handy. just flip to another screen and keep working. I simply can't live without this tool.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: StevenRiggins on Wed, Nov 5 2003 at 12:49PM PST
If you are using tcsh, you can:

setenv PAGER more

They default to using less now which clears the screen.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: jyu on Wed, Nov 5 2003 at 1:00PM PST
I'm confused. Why not just open the perference of Terminal and change from default to vt100? Open a new Terminal window and you will see the difference. No command line needed. Maybe there is something else you're trying to that I missed?

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: jyu on Wed, Nov 5 2003 at 1:03PM PST
Pls excuse my former comment. I didn't finish reading the whole hint.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: akapp on Wed, Nov 5 2003 at 2:34PM PST
Also fixes my Fkey problem. When telneted into my AIX box my Fkeys weren't working. This fixed it. Halleluya!

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: gospodin_david on Wed, Nov 5 2003 at 2:36PM PST
As a perhaps better solution, you can put "export LESS=X" in your .bashrc (I'd suppose you could put the equivalent in .tcshrc) and ending less won't clear the screen. This may be better in that some progams might have more functionality in xterm (like vim) than they do in vt100.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: gospodin_david on Wed, Nov 5 2003 at 2:39PM PST
sorry, I meant your .bash_profile. Actually put it whereever you would need to for whatever shell (login, interactive, non-login, etc.) you want.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: stevec on Wed, Nov 5 2003 at 2:46PM PST
A good solution except that doing so blew away my aliases and custom prompt. Did this happen to anyone else?

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: EatingPie on Wed, Nov 5 2003 at 3:09PM PST

Not sure what you did to cause this, since you're a subthread of the "LESS=X" branch.

One possibility is that Terminal works as a vt100, but bash still thinks you're xterm-color. Just do a "export TERM=vt100" and your colorization should return.

---
-Pie


[ Reply to This | # ]

10.3: Prevent Terminal from clearing screen after commands
Authored by: gospodin_david on Wed, Nov 5 2003 at 9:42PM PST
essentially, use whatever file you're using for initialization preferences and add that LESS=X to that file. It may be that by putting that line in .bashrc, another dotfile that you have all your settings in was ignored due to the presence of .bashrc.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: chancer on Thu, Nov 6 2003 at 11:49AM PST
Does anyone know what the .tcsh equivalent is?

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: vectors_to_final on Fri, Nov 7 2003 at 10:20AM PST
setenv LESS X

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: Accura on Thu, Nov 6 2003 at 5:40PM PST
Nice one, this is just what was needed.. Thanx from Down Under

Jameso

---
"The time has come," the walrus said. "To talk of many things..."

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: vogunaescht on Wed, Nov 5 2003 at 2:59PM PST
Just open the preferences of Terminal.app and set the terminal to declare itself as whatever is available (ansi, rxvt, vt52, vt100, vt102, cterm, xterm-color).

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: rogueleader on Wed, Nov 5 2003 at 3:21PM PST
If you use tcsh you can use this command to have less stop clearing the screen after quit.

 setenv PAGER '/usr/bin/less -X'
There is most likely a way to do it in bash.

rogue leader

[ Reply to This | # ]

10.3: Prevent Terminal from clearing screen after commands
Authored by: bhwagner on Wed, Nov 5 2003 at 3:35PM PST
This didn't work for me. However, the following line did:
setenv LESS -X

[ Reply to This | # ]
10.3: Prevent Terminal (bash) from clearing screen after commands
Authored by: hartkeks on Thu, Nov 6 2003 at 12:40AM PST
for bash add this to your ~/.bashrc

PAGER='/usr/bin/less -X'
export PAGER



[ Reply to This | # ]
Fixes screen too
Authored by: Morth on Wed, Nov 5 2003 at 5:45PM PST
Also screen segfaults (the latest dist version) with the default TERM setting. Doing this fixes that too.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: sjmills on Wed, Nov 5 2003 at 9:23PM PST
One things is still annoying or wrong after changing to ANSI, vt100, or vt102: If you do top and it fills the window, then ^C to stop it, you end up with your prompt overwriting the left part of the last line, but the rest of the top results appear after the prompt. Any way to fix that?

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: magenta on Thu, Nov 6 2003 at 2:25AM PST
Press ^L to refresh the screen afterwards. The vt100 terminal type doesn't support multiple screen buffers (which is basically waht this hint is disabling).

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: Graff on Thu, Nov 6 2003 at 10:30AM PST
I'm using tcsh and have my TERM set to xterm-color and my LESS set to -X. Everything seems to work just perfectly, with coloring and the expected behaviors for programs running in both the Terminal.app and the X11.app. You might want to try similar settings and see if it works to your satisfaction.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: Jim Hu on Sat, Nov 8 2003 at 2:37AM PST
Use q to exit top, not ^C

[ Reply to This | # ]
It's a bug, not a feature
Authored by: rae on Thu, Nov 6 2003 at 10:58AM PST
I noticed the screen-clearing problem and quickly set my terminal to 'dtterm' to fix it. However, even with Terminal in its default mode, the screen should not clear. This implies there is a bug in the terminfo entry in Panther.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: EatingPie on Thu, Nov 6 2003 at 4:35PM PST

I do want to note that the "LESS=X" fix only works for... well... less! The vi command still clears the screen when you use it with Terminal set to xterm-color.

The change to vt100 in your Terminal->Preferences is more of a global fix, and should effect everything. (This is probably obvious at this point, but I wanted to throw it out in the spirit of being thorough.)

---
-Pie


[ Reply to This | # ]

10.3: Prevent Terminal from clearing screen after commands
Authored by: Skurfer on Tue, Oct 5 2004 at 12:04AM PDT

This was killing me, but I found the solution. Adding the following line to your .vimrc file will keep Vim from clearing the screen when it exits.

set t_ti= t_te=

Switching to vt100 is no good for those of us that use something other than Terminal.app (i.e. log in remotely from a Solaris or Windows machine that has a less sophisticated understanding of vt100). By changing the behavior vi and less, you can stick with xterm-color, which is more consistently defined across platforms.



[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: thaislump on Thu, Nov 6 2003 at 5:13PM PST
Note that only a terminal setting of xterm-color with get you true syntax coloring in vim.

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: guybrush on Mon, Nov 10 2003 at 10:37AM PST
how about 'ms-vt100-color' ?

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: enigmamf on Wed, Sep 15 2004 at 2:02PM PDT
How about using gvim to edit stuff? :)

[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: ajg on Wed, Feb 8 2006 at 6:44PM PST
If you just want to stop vim clearing the screen, and you don't want to change your termcap/terminfo details, add the following to ~/.vimrc :

set t_ti= t_te=

This stops vim sending the control codes needed to perform screen switches.

[ Reply to This | # ]