【已解决】vim编辑状态下手残按了ctrl + z,怎么办?

文章目录

  • 一、问题过程描述
  • 二、解决


一、问题过程描述

不小心手残,按了ctrl + z,显示:

[1]+  Stopped                 vi db.json

输入vi db.json,显示了如下提示:

E325: ATTENTION
Found a swap file by the name ".db.json.swp"
          owned by: AImooc-Oliver   dated: Sun Jan 17 17:54:21 2021
         file name: /e/Projects/j-server/db.json
          modified: YES
         user name: AImooc-Oliver   host name: DESKTOP-QU2CUOV
        process ID: 163 (STILL RUNNING)
While opening file "db.json"
             dated: Sun Dec 12 17:51:26 2103

(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 db.json"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".db.json.swp"
    to avoid this message.

Swap file ".db.json.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

【已解决】vim编辑状态下手残按了ctrl + z,怎么办?_第1张图片

Using swap file ".db.json.swp"
Original file "/e/Projects/j-server/db.json"
Recovery completed. You should check if everything is OK.
(You might want to write out this file under another name
and run diff with the original file to check for changes)
You may want to delete the .swp file now.

Press ENTER or type command to continue

原来ctrl + z是强制将进程挂起,后台运行,会生成一个后缀为.swp的隐藏文件,接下来每次vi db.json都会显示上面那个界面。。。

二、解决

两种解决方案:

  • ctrl+z 退出后,在显示[1]+ Stopped vi db.json时,终端直接输入fg 1(中括号中显示的数字,即作业号,若只有一个,作业号可忽略)这样就会重回vim编辑界面了,然后正常退出即可。
  • ls -a 一下,会看到隐藏的.swp文件 删除了此文件即可,再次使用vim打开文件就不会出现上述界面了。

拓展阅读:

  • 【linux】bg和fg命令的学习

你可能感兴趣的:(vim,fg,job,linux,ctrl,z)