2009-11-04 42 views
11

是否有可能在vim退出前使用類似「vim-close/exit」-Event的命令來執行某些最後的命令?.vimrc動作關閉

我用這個線在我的配置,讓VIM設置我的屏幕標題:

如果$ TERM == '的xterm色'

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

ENDIF

但是當我關閉vim時,標題被設置爲:「感謝飛行Vim」(無論來自哪裏......)

我的目標是,將標題重置爲舊的 - 如果可能 - 如果沒有 - 設置爲類似「bash」的那個「exe」 - 命令

所以..有沒有像「close - 事件「在VIM?

謝謝:)

回答

12

是的,有一個「關閉事件」 - 其實是其中兩個。
引述vim的:幫助{}事件

  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 

你是VimLeave - 活動後。
工作示例如下:

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() 

此外,還可以使用五:死亡趕上異常退出的情況。

+0

大大方方的感謝名單...有點我發現VimLeave沒有工作後冷靜的選擇: 讓&titleold =替代品(GETCWD(),$ HOME, 「〜」, '') VIM似乎有它在退出時恢復:) 現在它設置〜/我的/路徑 這就是酷:) – Beerweasle 2009-11-04 13:42:36

+0

@Beerweasle你的評論是不完全正確的,它應該是'let&titleold = substitute(getcwd(),$ HOME,「〜」,「」)' 但是,非常感謝這個主意! – Alf 2016-07-10 10:43:54