退出 Byobu 时,关闭所有未退出的 vim 会话

退出 Byobu 时,关闭所有未退出的 vim 会话

我已将 Byobu 配置为在启动时打开十几个文本文件:

new-session -n memo /home/nico/bin/vim-my-memo.sh;
new-window -n client1 /home/nico/bin/vim-client1.sh;
[...]

它运行良好,但是每当我需要关闭计算机时关闭所有 vim 会话会花费太多时间,所以我通过单击左上角的红色 X 按钮来关闭整个 Byobu。

问题:当我重新打开 Byobu 时,所有 vim 会话都显示:

E325: ATTENTION
Found a swap file by the name "~/.memo.txt.swp"
          owned by: nico   dated: Fri Jul 17 21:18:38 2015
         file name: ~nico/memo.txt
          modified: no
         user name: nico   host name: nico
        process ID: 21813 (still running)
While opening file "/home/nico/memo.txt"
             dated: Fri Jul 17 21:08:32 2015

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /home/nico/memo.txt"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/home/nico/.memo.txt.
swp"
    to avoid this message.

Swap file "~/d/n/.memo.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

问题:如何避免这种情况?

也许 Byobu 可以以某种方式向 vim 发送终止信号,使其正常退出?
或者也许只需要一些 vim 配置/技巧?

答案1

set noswapfile在您的 vimrc 文件中使用(或:set noswapfile其他方式)可能会产生一些不必要的副作用,但从 vim 方面来说可以解决问题。

我不知道 byobu,但如果您可以自定义它以将退出信号 3 ( kill -3 vimprocess) 发送到所有 vim 进程,那就可以了。

编辑:tmux 插件位于https://github.com/jlipps/tmux-safekill将执行您想要的操作(以及更多:请参阅 safekill.sh 脚本进行自定义),而没有 的缺点set noswapfile

相关内容