如果vim被异常关闭,再次打开相同文件时,会报错:
"E325: ATTENTION
Found a swap file by the name "/var/tmp/list.c.swp"
owned by: xxx dated: Thu Nov 27 12:26:12 2025
file name: /data/git/lihuiqin/agf_v70_makefile_DS/agm_v77_78_singly_Linked_List_head/list.c
modified: no
user name: xxx host name: zzz
process ID: 74113 (STILL RUNNING)
While opening file "list.c"
dated: Sun Nov 23 17:21:53 2025
(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 list.c"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/var/tmp/list.c.swp"
to avoid this message.
Swap file "/var/tmp/list.c.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:"
可以按照如下步骤处理:
1, 查看原有终端是否还存在
w
或
who
2,根据报错信息的“process ID: 74113 (STILL RUNNING)” 查看进程
ps aux | grep 74113
或者
ps -p 74113
3,如果找不到原终端,或它已断开
3.1 给 Vim 进程发送保存并退出的信号(尝试优雅关闭)
kill -TERM 74113
-TERM 是发送的信号类型,这里的 TERM 表示 “terminate”,即请求进程终止。
大多数进程会在收到 TERM 信号后进行清理工作并优雅地退出。
3.2 等待几秒后检查进程是否还在
ps -p 74113
3.3 如果进程还在,强制终止
kill -9 74113
4, 恢复未保存的修改
如果进程不存在或已僵死,
4.1先尝试恢复未保存的更改(在删除 swp 之前!)
vim -r list.c
查看内容,如果有未保存的修改,就 :wq 保存;
4.2 确认恢复完成后,再删除交换文件
rm /var/tmp/list.c.swp
然后再重新打开文件
vim list.c
4426

被折叠的 条评论
为什么被折叠?



