1. 程式人生 > >vim檔案時,誤用了ctrl+z命令,該怎麼辦?

vim檔案時,誤用了ctrl+z命令,該怎麼辦?

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 退出命令即可