问题 .vimrc动作onclose


是否可以使用类似“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>\\"

万一

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

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

所以...在vim中有类似“近距离事件”的东西吗?

谢谢 :)


6533
2017-11-04 13:08


起源



答案:


是的,有一个“近距离事件” - 实际上有两个。
引用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

你是在追求 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()

另外你可以使用 五:死亡 捕捉异常退出案件。


12
2017-11-04 13:18



在VimLeave没有工作之后我发现了一个很酷的选择:让&titleold =替换(getcwd(),$ HOME,“〜”,'')vim似乎有一个titleold,它恢复了退出:)现在它设置〜/ my / path这很酷:) - Beerweasle
@Beerweasle你的评论不完全正确,应该是 let &titleold=substitute(getcwd(), $HOME, "~", "")  但是非常感谢这个想法!! - Alf


答案:


是的,有一个“近距离事件” - 实际上有两个。
引用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

你是在追求 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()

另外你可以使用 五:死亡 捕捉异常退出案件。


12
2017-11-04 13:18



在VimLeave没有工作之后我发现了一个很酷的选择:让&titleold =替换(getcwd(),$ HOME,“〜”,'')vim似乎有一个titleold,它恢复了退出:)现在它设置〜/ my / path这很酷:) - Beerweasle
@Beerweasle你的评论不完全正确,应该是 let &titleold=substitute(getcwd(), $HOME, "~", "")  但是非常感谢这个想法!! - Alf