使用vim編輯文件時,超時退出終端,或者沒有退出直接關閉終端,造成異常退出的場景,再次編輯時會報以下錯誤:
E325: ATTENTION
Found a swap file by the name ".test.txt.swp"
owned by: root dated: Thu Jun 27 14:38:06 2019
file name: ~root/test.txt
modified: YES
user name: root host name: VMcentos
process ID: 20994
While opening file "test.txt"
dated: Thu Jun 27 13:42:52 2019
(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 test.txt"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".test.txt.swp"
to avoid this message.
Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
使用ll -a 命令查看一下,確實有一個隱藏文件,原來在編輯文件時,系統會copy一份臨時文件.test.txt.swap,也會對這個文件進行編輯,執行:w時纔會將臨時文件中的內容寫入到正式文件,執行:q時纔會將臨時文件刪除。
解決辦法:
將.test.txt.swap文件刪除,rm .test.txt.swap