Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 2.40 / 5
  You rated: 1 / 5 (10 votes cast)
 
[20,028 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 whoever posted them. This site is not responsible for what they say.
10.3: Prevent Terminal from clearing screen after commands
Authored by: sharumpe on Nov 05, '03 11:33:16AM

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 Nov 05, '03 12:27:36PM

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 Nov 05, '03 12:04:03PM
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 Nov 05, '03 12:49:09PM

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 Nov 05, '03 01:00:26PM

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 Nov 05, '03 01:03:27PM

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 Nov 05, '03 02:34:16PM

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 Nov 05, '03 02:36:39PM

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 Nov 05, '03 02:39:49PM

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 Nov 05, '03 02:46:01PM
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 Nov 05, '03 03:09:36PM

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 Nov 05, '03 09:42:45PM

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 Nov 06, '03 11:49:21AM

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 Nov 07, '03 10:20:37AM

setenv LESS X



[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: Accura on Nov 06, '03 05:40:17PM

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 Nov 05, '03 02:59:23PM

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 Nov 05, '03 03:21:10PM
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 Nov 05, '03 03:35:09PM
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 Nov 06, '03 12:40:05AM
for bash add this to your ~/.bashrc

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



[ Reply to This | # ]
Fixes screen too
Authored by: Morth on Nov 05, '03 05:45:33PM

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 Nov 05, '03 09:23:21PM
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 Nov 06, '03 02:25:05AM

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 Nov 06, '03 10:30:37AM

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 Nov 08, '03 02:37:23AM

Use q to exit top, not ^C



[ Reply to This | # ]
It's a bug, not a feature
Authored by: rae on Nov 06, '03 10:58:27AM

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 Nov 06, '03 04:35:04PM

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 Oct 05, '04 12:04:38AM

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 Nov 06, '03 05:13:56PM

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 Nov 10, '03 10:37:57AM

how about 'ms-vt100-color' ?



[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: enigmamf on Sep 15, '04 02:02:55PM

How about using gvim to edit stuff? :)



[ Reply to This | # ]
10.3: Prevent Terminal from clearing screen after commands
Authored by: ajg on Feb 08, '06 06:44:17PM

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 | # ]