Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.vimrc action onclose

Tags:

bash

vim

is it possible to use something like an "vim-close/exit"-Event to execute some last commands before vim quits?

I use this lines in my config, to let vim set my screen-title:

if $TERM=='xterm-color'

 exe "set title titlestring=vim:%t"
 exe "set title t_ts=\<ESC>k t_fs=\<ESC>\\"

endif

but when i close vim, the title is set to: "Thanks for flying Vim" (whereever that comes from...)

My goal is, to reset the title to the old one - if possible - and if not - set is to something like "bash" with that "exe"-Command

So.. is there something like an "close-event" in vim?

Thanks :)

like image 284
Beerweasle Avatar asked Nov 04 '09 13:11

Beerweasle


1 Answers

Yes, there is a "close-event" -- actually two of them.
To quote vim's :help {event}:

            Startup and exit
|VimEnter|              after doing all the startup stuff
|GUIEnter|              after starting the GUI successfully
|TermResponse|    after the terminal response to |t_RV| is received

|VimLeavePre|        before exiting Vim, before writing the viminfo file
|VimLeave|              before exiting Vim, after writing the viminfo file

You're after the VimLeave-Event.
A working sample looks like this:

function! ResetTitle()
    " disable vim's ability to set the title
    exec "set title t_ts='' t_fs=''"

    " and restore it to 'bash'
    exec ":!echo -e '\033kbash\033\\'\<CR>"
endfunction

au VimLeave * silent call ResetTitle()

In addition you can use v:dying to catch abnormal exit cases.

like image 51
Shirkrin Avatar answered Oct 02 '22 12:10

Shirkrin