红联Linux门户
Linux帮助

linux:vim异常终端处理办法

发布时间:2017-01-15 09:53:25来源:linux网站作者:cfqcfqcfqcfqcfq
vim异常终端后,再次进入相同文件编辑时候会出现如下提示:
(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 man.config"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".man.config.swp"
to avoid this message.
 
这里是说vim中断的两种可能:
1.可能有其他人或程序同时在编辑这个档案
这种情况下可以选择只读模式进去浏览文档但不能对文档更改
2.在前一个 vim 的环境中,可能因为某些不知名原因导致 vim 中断 (crashed)
 
在提示最后一行会给出菜单项进行选择:
[O]pen Read-Only, (E)dit anyway, (R)ecover,  (Q)uit, (A)bort:
选择任何一项都会进入到vim编辑器。但你退出后再次进入,仍然回存在相应的提示信息。  
原因是 vim异常中断时候,会将我们的修改保存在一个缓存文件中(.swp)。因为文档与缓存文档不一致,所以每次进入都会提示信息。
异常中断除了产生了swp文件,还有可能有swo文件。
 
解决办法:
1.打开缓存文件,将其保存退出,然后删除缓存文件。
 
2.如果想要忽略上次修改的内容,可以直接删除缓存文件即可。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/27814.html