Vim打不开文件:Another program may be editing the same file./An edit session for this file crashed.

Linux 下用 Vim 打开一个脚本文件“f03.sh”,直接报错:

vim f03.sh

遇到英文错误不要怕,先看一下报错的内容。

  • Another program may be editing the same file.
  • An edit session for this file crashed.
    在这里插入图片描述
E325: ATTENTION
Found a swap file by the name ".f03.sh.swp"
          owned by: geofferysun   dated: Wed Apr 28 14:28:12 2021
         file name: ~geofferysun/NDK/New/f03.sh
          modified: YES
         user name: geofferysun   host name: LAPTOP-G599D37H
        process ID: 139 (STILL RUNNING)
While opening file "f03.sh"
             dated: Wed Apr 28 15:59:15 2021
      NEWER than swap file!

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

解决思路: Linux 下两个人同时打开同一个文件会显示如下界面,而有的时候只有一个账户的时候也有这个提示,此时的处理思路是由于上次没有关闭打开的文件造成的,结束掉进程即可。

一、结束进程

  1. 查看 vi 进程
ps -ef | grep vi
geofferysun@LAPTOP-G599D37H:~/NDK/New$ ps -ef |grep vi
geoffer+   139     8  0 14:27 tty1     00:00:00 vim f03.sh
geoffer+   202     8  0 16:12 tty1     00:00:00 grep --color=auto vi

8个字段的含义:

UIDPIDPPIDCSTIMETTYTIMECMD
geoffer+1398014:27tty100:00:00vim f03.sh
geoffer+2028016:12tty100:00:00grep --color=auto vi
  • UID:程序被该 UID 所拥有
  • PID:就是这个程序的 ID
  • PPID:则是其上级父程序的ID
  • C:CPU使用的资源百分比
  • STIME:系统启动时间
  • TTY:登入者的终端机位置
  • TIME:使用掉的CPU时间。
  • CMD:所下达的是什么指令
  1. 结束掉指定(PID为139)进程
kill -9 139

如果结束进程后仍然有这个提示,此时是由于缓存造成的删除缓存即可。

二、清除上次操作留下的缓存

“f03.sh” 文件后面添加 “.swp”,可以 tab 键补齐出来

 rm -rf .f03.sh.swp

此时再打输入开文件指令即可恢复正常。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小山研磨代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值