当前位置: 代码迷 >> 综合 >> vim编辑文件出错 swap file “*.swp”already exists!
  详细解决方案

vim编辑文件出错 swap file “*.swp”already exists!

热度:14   发布时间:2023-11-30 17:30:57.0

在linux中使用vim编辑文件时,很常见的一个问题,若没有正确定的退出编辑,系统会生成一个隐藏文件为.**.swp,此时若再次进入编辑,都会提示错误If you did this already, delete the swap file ".**.swp",若要想再次正确编辑文件和对后面工作不进行影响,必须先删除.**.swp文件。
错误信息如下:

......
......
(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 samefile 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 11-1.c"to recover the changes (see ":help recovery").If you did this already, delete the swap file ".11-1.c.swp"to avoid this message.Swap file ".11-1.c.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: 

解决办法,切换到编辑文件所在的目录下,然后执行:
[如果目录下文件过于多可以直接使用   rm -rf .**.swp]

[root@king playbook]# ls -a  //查看所有文件包括隐藏文件
[root@king playbook]# ls -a
.  ..  play.yml  .play.yml.swp
[root@king playbook]# rm -rf .play.yml.swp

再次vi/vim编辑进去就不会报问题!

  相关解决方案