学习shell与shell script 02_vim 的保存恢复与打开时的警告信息

[1]+  Stopped                 vim test.txt
$kill -9 %1

[1]+  Stopped                 vim test.txt
$jobs
[1]+  Killed                  vim test.txt

编辑一个文件后,使用Ctrl + z 挂起。然后被不正常中断,导致暂存盘无法通过正常的流程来结束。所以暂存文件就不会消失,而继续保留下来。

Found a swap file by the name ".test.txt.swp"
          owned by: ubuntu   dated: 三 1月 25 14:13:01 2023
         file name: ~ubuntu/test.txt
          modified: YES
         user name: ubuntu   host name: ubuntu-virtual-machine
        process ID: 2287
While opening file "test.txt"
             dated: 三 1月 25 14:11:55 2023

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

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

问题一:可能有其他人或程序同时在编辑这个文件

linux是多人多任务的环境,因此很可能很多人同时在编辑同一个文件。

先找到另外那个程序员,请他将该vim的工作结束,然后你再继续处理;

这个时候,你可以选择一只读方式打开O。Open Read-Only

问题二:在前一个vim的环境中,可能因为某些不明原因导致vim中断(crash)

这个是常见的不正常结束vim 产生的后果。解决方案依据不同的情况而不同。

1)R Recover的意思,此时vim 会载入.filename.swp的文件内容。让你自己决定要不要保存。

不过.filename.swp的文件不会自动删除,需要你手动删除,这样子可以避免每次打开这个文件都会有这个提示

2)如果确认临时文件无用,可以使用D删除这个临时文件,这个时候,会载入man.config,并将旧的.man.config.swp删除后,新建这次会使用新的.filename.swp

Open Read-Only

打开此文件成为只读文件,可以用在你只想要查阅该文件的内容。

比如登录到同学电脑查看配置文件,结果发现对方正在编辑时候,可以使用这个模式。

Edit anyway

还是使用正常方式打开你要编辑的文件,并不会载入暂存的文件。不过很容易出现两个用户互改变

对方的文件等问题

Recover

就是加载临时文件的内容,用在你救回之前未保存的工作。不过当你救回来并保存离开vim后,需要手动删除那个暂存文件

Delete it 

直接删除暂存的文件的内容,用在你要救回之前未保存的工作。这个比较常见,因为你不确定这个暂存文件是怎么来的。所以删除他

Quit

退出,不做任何操作

Abort

忽略这个编辑行为,感觉上与quit非常类似

打开test.txt

Ctrl + z 将vim后台挂起,然后使用kill -9  %1来模拟vim非正常中断。

[1]+  Stopped                 vim test.txt
$kill -9 %1

[1]+  Stopped                 vim test.txt

E325: ATTENTION
Found a swap file by the name ".test.txt.swp"
          owned by: ubuntu   dated: 三 1月 25 15:13:01 2023
         file name: ~ubuntu/test.txt
          modified: YES
         user name: ubuntu   host name: ubuntu-virtual-machine
        process ID: 61570
While opening file "test.txt"
             dated: 三 1月 25 15:11:54 2023

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

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

使用R  Recover

发现内容是非正常中断之前的内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值