.vimrc动作onclose

Bee*_*sle 11 vim bash

是否可以使用类似"vim-close/exit"-Event的东西在vim退出之前执行最后的命令?

我在配置中使用这一行,让vim设置我的屏幕标题:

if $ TERM =='xterm-color'

 exe "set title titlestring=vim:%t"
 exe "set title t_ts=\<ESC>k t_fs=\<ESC>\\"
Run Code Online (Sandbox Code Playgroud)

万一

但当我关闭vim时,标题设置为:"感谢飞行Vim"(不管是来自......)

我的目标是,将标题重置为旧标题 - 如果可能 - 如果不可能 - 设置为"bash"与"exe"-Command

所以...在vim中有类似"关闭事件"的东西吗?

谢谢 :)

Shi*_*rin 12

是的,有一个"近距离事件" - 实际上有两个.
引用vim :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
Run Code Online (Sandbox Code Playgroud)

你是在VimLeave -Event之后.
一个工作样本看起来像这样:

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()
Run Code Online (Sandbox Code Playgroud)

此外,您可以使用v:dying来捕获异常退出情况.