vim文件时,误用了ctrl+z命令,该怎么办?

linux中,当正在使用vim命令编辑文件,退出时,如果误使用了 ctrl+z ,当前目录中会多一个隐藏文件。

比如我正在编辑 t.txt 文件时,误以为我之前使用的是 tail 命令,直接使用 ctrl+z 命令退出。

但是就用错了,那么当前目录就会多一个隐藏文件

image-20190825222532676

当再次编辑 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 退出命令即可。

posted @ 2019-08-25 23:30  linupy  阅读(3340)  评论(0编辑  收藏  举报