linux中,當正在使用vim命令編輯文件,退出時,如果誤使用了 ctrl+z
,當前目錄中會多一個隱藏文件。
比如我正在編輯 t.txt
文件時,誤以為我之前使用的是 tail
命令,直接使用 ctrl+z
命令退出。
但是就用錯了,那么當前目錄就會多一個隱藏文件
當再次編輯 t.txt
文件時,就會提示
E325: 注意
發現交換文件 ".t.txt.swp"
所有者: root 日期: Sun Aug 25 23:27:33 2019
文件名: ~root/test/t.txt
修改過: 否
用戶名: root 主機名: master
進程 ID: 4803 (仍在運行)
正在打開文件 "t.txt"
日期: Sun Aug 25 22:17:30 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.
如果是這樣,請用 ":recover" 或 "vim -r t.txt"
恢復修改的內容 (請見 ":help recovery")。
如果你已經進行了恢復,請刪除交換文件 ".t.txt.swp"
以避免再看到此消息。
交換文件 ".t.txt.swp" 已存在!
以只讀方式打開([O]), 直接編輯((E)), 恢復((R)), 退出((Q)), 中止((A)):
此時的解決辦法是,使用 fg
命令即可
為什么?
ctrl + z
可以將一個正在前台執行的命令放到后台,並且暫停
fg
將后台中的命令調至前台繼續運行
將后台命令調至前台繼續運行后,在使用, vim 退出命令即可。