2009-11-04 70 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