clear screen on quit on filetype

0 views
Skip to first unread message

Noah Spurrier

unread,
Nov 18, 2008, 4:13:18 PM11/18/08
to vim_use googlegroups.com
Can someone suggest a way I can do the following?
For certain filetypes I would like to have the screen cleared before
Vim quits back to the shell prompt. For most filetypes I DO NOT want
Vim to clear the screen. Is this getting too tricky?

--
Noah Spurrier | email:no...@noah.org | http://www.noah.org/wiki/engineering
----------------------------------------------------------------------------

Chris Suter

unread,
Nov 18, 2008, 5:01:47 PM11/18/08
to vim...@googlegroups.com
create a wrapper script  for /usr/bin/vim containing the following:


#!/bin/bash

/usr/bin/vim $1
if [[ -f /tmp/was_editing_certain_type_of_file ]]
then
    rm /tmp/was_editing_certain_type_of_file && clear
fi


then, in your ~/.vimrc, add the following (assume you want to do this for anything matching *.txt):


au BufNewFile,BufRead *.txt call PrepareForClear()

function! PrepareForClear()
    au! VimLeave * execute "!touch /tmp/was_editing_certain_type_of_file"
endfunction


this worked on my machine -- the wrapper script above will work on bash and zsh, but i don't know about other shells. the basic idea is the same, though.


HTH,
chris
--
Christopher Suter

Gary Johnson

unread,
Nov 18, 2008, 5:36:00 PM11/18/08
to vim...@googlegroups.com
On 2008-11-18, Noah Spurrier <no...@noah.org> wrote:
> Can someone suggest a way I can do the following?
> For certain filetypes I would like to have the screen cleared before
> Vim quits back to the shell prompt. For most filetypes I DO NOT want
> Vim to clear the screen. Is this getting too tricky?

There are a couple of ways to approach this, depending on what you
mean by "clear". If want to restore the screen to the contents it
had prior to executing vim, that behavior is controlled, in part, by
the 't_ti' and 't_te' options. See

:help terminal-options
:help restorescreen
:help raw-terminal-mode
:help xterm-save-screen

You could leave the 't_ti' and 't_te' values alone for filetypes for
which you wanted the screen restored, and clear them for filetypes
for which you wanted to leave the screen as it was just before
quitting vim. To clear them, just put this line in the appropriate
after/ftplugin files:

set t_ti= t_te=

If by "clear" you mean really clear the screen as though you had
executed the "clear" command just after exiting vim, you could put a
set of autocommands like these in your ~/.vimrc:

au VimLeave * if &ft == "filetypeA" | !clear | endif
au VimLeave * if &ft == "filetypeB" | !clear | endif

For those to work, you may also have to put this in your .vimrc:

set t_ti= t_te=

HTH,
Gary

Reply all
Reply to author
Forward
0 new messages