在 Linux 下的 vi
编辑过程中,由于某种原因异常退出正在编辑的文件,再次编辑该文件时,会出现如下提示:
E325: ATTENTION
Found a swap file by the name ".test1.sh.swp"
owned by: lee dated: Sat Oct 31 10:49:13 2020
file name: ~lee/shell_test/test1.sh
modified: YES
user name: lee host name: localhost.localdomain
process ID: 55555
While opening file "test1.sh"
dated: Mon Jan 11 14:24:56 2021
NEWER than swap file!
(1) Another program may be editing the same file. If this
is the case,
be careful not to end up with two different instances o
f the same
file when making changes. Quit, or continue with cauti
on.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r test1.sh
"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".test1.s
h.swp"
to avoid this message.
Swap file ".test1.sh.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q
)uit, (A)bort:
这是因为使用vi编辑文件实际是先 copy 一份临时文件并映射到内存给你编辑, 编辑的是临时文件,;
当执行:w 后才保存临时文件到原文件,执行:q 后才删除临时文件。
每次启动检索是否有临时文件, 有则询问如何处理,就会出现如上情景,换言之就是你在上一次编辑过程中因一些莫名原因强制退出了正在编译的文件导致的(切记保留规范的开发使用习惯)。
解决办法:
删除临时文件*.swp
[lee@localhost shell_test]$ ll -a
total 20
drwxrwxr-x 2 lee lee 43 Jan 11 14:31 .
drwx------. 22 lee lee 4096 Jan 11 14:31 ..
-rw-rw-r-- 1 lee lee 33 Jan 11 14:24 test1.sh
-rw-r--r-- 1 lee lee 12288 Oct 31 10:49 .test1.sh.swp
[lee@localhost shell_test]$ rm -f .test1.sh.swp
[lee@localhost shell_test]$ ll -a
total 8
drwxrwxr-x 2 lee lee 22 Jan 11 14:31 .
drwx------. 22 lee lee 4096 Jan 11 14:31 ..
-rw-rw-r-- 1 lee lee 33 Jan 11 14:24 test1.sh
此时就能重新vi
了