前言
使用vim的時候,文件編輯過程中可能會出現bug,導致非正常關閉。為了保存剛剛修改的內容,需要對文件進行恢復。
操作過程
1.查看目錄文件
zrj@zrj-ThinkPad-E470:~/work/code/facedetection/src$ ll total 48 drwxrwxr-x 2 xxx xxx 4096 Sep 11 16:48 ./ drwxrwxr-x 6 xxx xxx 4096 Sep 11 12:23 ../ -rw-rw-r-- 1 xxx xxx 10859 Sep 11 16:48 facedet.cpp -rw-r--r-- 1 xxx xxx 20480 Sep 11 16:43 .facedet.cpp.swp -rw-rw-r-- 1 xxx xxx 6346 Sep 11 16:44 facedet_test.cpp
發現多了個swap文件。
2.問題描述
E325: ATTENTION Found a swap file by the name ".facedet.cpp.swp"owned by: xxx dated: Tue Sep 11 16:59:21 2018file name: ~xxx/work/code/facedetection/src/facedet.cppmodified: nouser name: xxx host name: xxx-ThinkPad-E470process ID: 22229 (still running) While opening file "facedet.cpp"dated: Tue Sep 11 16:55:31 2018(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 samefile 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 facedet.cpp"to recover the changes (see ":help recovery").If you did this already, delete the swap file ".facedet.cpp.swp"to avoid this message.Swap file ".facedet.cpp.swp" already exists! [O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:
3.原因分析
a.文件非正常關閉;
b.另一個Terminal也在編輯同一個文件;
?
4解決方法
a.非正常關閉;
使用recover覆蓋文件,再刪除swap文件;
1. vim -r facedet.cpp 2. rm .facedet.cpp.swp
b.同時編輯同一個文件;
先關閉一個文件再編輯另一個,注意避免同時編輯同一個文件;
注意,修改文件時請注意避免同一個文件產生兩個不同的版本。
參考
1.csdn博客;
完