开发者

.vimrc action onclose

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 t开发者_JAVA百科itle 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 :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜