Vim提示E325(锁机制)

背景

用vim命令处理一些超大文件时,有时会遇到卡死现象,不得不强制退出。但是,再次用vim命令访问这个文件时,会出现“E325:ATTENTION”提示。如果不做处理,以后每次都会出现。

分析

经过一番查证,此提示是vim程序对文件的一种保护机制(或锁机制)。当我们用vim命令打开一个文件时,会自动生成一个隐藏的swp文件。如果vim还在处理此文件,或者由于一些原因未正常退出,swp文件就会一直存在。当我们再次用vim命令打开此文件时,程序检测到有swp文件存在,就提醒我们不要误操作。原文如下:

*

11.3*	Crashed or not?					*

ATTENTION* *

E325*

Vim tries to protect you from doing stupid things.  Suppose you innocently
start editing a file, expecting the contents of the file to show up.  Instead,
Vim produces a very long message:

		E325: ATTENTION 
	Found a swap file by the name ".main.c.swp" 
		  owned by: mool   dated: Tue May 29 21:09:28 2001 
		 file name: ~mool/vim/vim6/src/main.c 
		  modified: no 
		 user name: mool   host name: masaka.moolenaar.net 
		process ID: 12559 (still running) 
	While opening file "main.c" 
		     dated: Tue May 29 19:46:12 2001 

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

You get this message, because, when starting to edit a file, Vim checks if a
swap file already exists for that file.  If there is one, there must be
something wrong.  It may be one of these two situations.

1. Another edit session is active on this file.  Look in the message for the
   line with "process ID".  It might look like this:

		process ID: 12559 (still running) 

   The text "(still running)" indicates that the process editing this file
   runs on the same computer.  When working on a non-Unix system you will not
   get this extra hint.  When editing a file over a network, you may not see
   the hint, because the process might be running on another computer.  In
   those two cases you must find out what the situation is yourself.
      If there is another Vim editing the same file, continuing to edit will
   result in two versions of the same file.  The one that is written last will
   overwrite the other one, resulting in loss of changes.  You better quit
   this Vim.

2. The swap file might be the result from a previous crash of Vim or the
   computer.  Check the dates mentioned in the message.  If the date of the
   swap file is newer than the file you were editing, and this line appears:

		modified: YES 

   Then you very likely have a crashed edit session that is worth recovering.
      If the date of the file is newer than the date of the swap file, then
   either it was changed after the crash (perhaps you recovered it earlier,
   but didn‘t delete the swap file?), or else the file was saved before the
   crash but after the last write of the swap file (then you‘re lucky: you
   don‘t even need that old swap file).  Vim will warn you for this with this
   extra line:

      NEWER than swap file! 

UNREADABLE SWAP FILE

Sometimes the line

	[cannot be read] 

will appear under the name of the swap file.  This can be good or bad,
depending on circumstances.

It is good if a previous editing session crashed without having made any
changes to the file.  Then a directory listing of the swap file will show
that it has zero bytes.  You may delete it and proceed.

It is slightly bad if you don‘t have read permission for the swap file.  You
may want to view the file read-only, or quit.  On multi-user systems, if you
yourself did the last changes under a different login name, a logout
followed by a login under that other name might cure the "read error".  Or
else you might want to find out who last edited (or is editing) the file and
have a talk with them.

It is very bad if it means there is a physical read error on the disk
containing the swap file.  Fortunately, this almost never happens.
You may want to view the file read-only at first (if you can), to see the
extent of the changes that were "forgotten".  If you are the one in charge of
that file, be prepared to redo your last changes.

WHAT TO DO?					*

swap-exists-choices*

If dialogs are supported you will be asked to select one of five choices:

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

O  Open the file readonly.  Use this when you just want to view the file and
   don‘t need to recover it.  You might want to use this when you know someone
   else is editing the file, but you just want to look in it and not make
   changes.

E  Edit the file anyway.  Use this with caution!  If the file is being edited
   in another Vim, you might end up with two versions of the file.  Vim will
   try to warn you when this happens, but better be safe then sorry.

R  Recover the file from the swap file.  Use this if you know that the swap
   file contains changes that you want to recover.

Q  Quit.  This avoids starting to edit the file.  Use this if there is another
   Vim editing the same file.
      When you just started Vim, this will exit Vim.  When starting Vim with
   files in several windows, Vim quits only if there is a swap file for the
   first one.  When using an edit command, the file will not be loaded and you
   are taken back to the previously edited file.

A  Abort.  Like Quit, but also abort further commands.  This is useful when
   loading a script that edits several files, such as a session with multiple
   windows.

D  Delete the swap file.  Use this when you are sure you no longer need it.
   For example, when it doesn‘t contain changes, or when the file itself is
   newer than the swap file.
      On Unix this choice is only offered when the process that created the
   swap file does not appear to be running.

If you do not get the dialog (you are running a version of Vim that does not
support it), you will have to do it manually.  To recover the file, use this
command:

	:recover

Vim cannot always detect that a swap file already exists for a file.  This is
the case when the other edit session puts the swap files in another directory
or when the path name for the file is different when editing it on different
machines.  Therefore, don‘t rely on Vim always warning you.

If you really don‘t want to see this message, you can add the ‘A‘ flag to the
‘shortmess‘ option.  But it‘s very unusual that you need this.

For remarks about encryption and the swap file, see |:recover-crypt|.

==============================================================================

解决

因为我是未正常退出vim程序导致,而且我要编辑的文件是正常的,所以直接将sep文件删除(选择(D)elete it)即可。你也根据自己的实际情况做选择吧。

参考

vim命令文档:http://vimdoc.sourceforge.net/htmldoc/usr_11.html
时间: 2024-10-11 09:15:04

Vim提示E325(锁机制)的相关文章

并发编程(四):也谈谈数据库的锁机制

http://www.2cto.com/database/201403/286730.html 1. 数据库并发的问题 数据库带来的并发问题包括: 1. 丢失更新. 2. 未确认的相关性(脏读). 3. 不一致的分析(非重复读). 4. 幻像读. 详细描述如下: 1.1.丢失更新 当两个或多个事务选择同一行,然后基于最初选定的值更新该行时,会发生丢失更新问题.每个事务都不知道其它事务的存在.最后的更新将重写由其它事务所做的更新,这将导致数据丢失. e.g.事务A和事务B同时修改某行的值, 事务A

【Hibernate步步为营】--锁机制详解

上篇文章详细讨论了hql的各种查询方法,在讨论过程中写了代码示例,hql的查询方法类似于sql,查询的方法比较简单,有sql基础的开发人员在使用hql时就会变得相当的简单.Hibernate在操作数据库的同时也提供了对数据库操作的限制方法,这种方法被称为锁机制,Hibernate提供的锁分为两种一种是乐观锁,另外一种是悲观锁.通过使用锁能够控制数据库的并发性操作,限制用户对数据库的并发性的操作. 一.锁简介 锁能控制数据库的并发操作,通过使用锁来控制数据库的并发操作,Hibernate提供了两种

SqlServer锁机制与实践

在如今这个云计算,大数据,移动互联网大行其道的时代,各种NoSQL数据库MongoDb.redis.HBase等使用的越来越广泛,大有替代关系型数据库的趋势.但是关系型数据库真的已经落伍了吗?答案是否定的.非关系型数据库不支持ACID属性,不支持事务,无法适应复杂查询的缺点.关系型数据库凭借其强一致性的特点,注定了在类似银行转账,订单支付等场景中,还是唯一的选择.众所周知,SQLSERVER通过锁来提供ACID属性,处理并发访问,本文尝试通过对锁机制的一些学习,让我们明白数据库查询超时,死锁等问

SQL锁机制和事务隔离级别

摘自:http://www.cnblogs.com/haiyang1985/archive/2009/02/27/1399641.html 锁机制 NOLOCK和READPAST的区别. 1.       开启一个事务执行插入数据的操作. BEGIN TRAN t INSERT INTO Customer SELECT 'a','a' 2.       执行一条查询语句. SELECT * FROM Customer WITH (NOLOCK) 结果中显示"a"和"a&quo

【Hibernate步步为营】--锁机制具体解释

上篇文章具体讨论了hql的各种查询方法.在讨论过程中写了代码演示样例.hql的查询方法类似于sql,查询的方法比較简单,有sql基础的开发者在使用hql时就会变得相当的简单. Hibernate在操作数据库的同一时候也提供了对数据库操作的限制方法.这样的方法被称为锁机制,Hibernate提供的锁分为两种一种是乐观锁.第二种是悲观锁. 通过使用锁可以控制数据库的并发性操作.限制用户对数据库的并发性的操作. 一.锁简单介绍 锁能控制数据库的并发操作,通过使用锁来控制数据库的并发操作,Hiberna

mysql锁机制(转载)

锁是计算机协调多个进程或线程并发访问某一资源的机制 .在数据库中,除传统的 计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是所有数据库必须解决的一 个问题,锁冲突也是影响数据库并发访问性能的一个重要因素. 从这个角度来说,锁对数据库而言显得尤其重要,也更加复杂.本章我们着重讨论MySQL锁机制 的特点,常见的锁问题,以及解决MySQL锁问题的一些方法或建议. MySQL锁概述相对其他数据库而言,MySQL的锁机制比较简单,

大话Linux内核中锁机制之内存屏障、读写自旋锁及顺序锁

大话Linux内核中锁机制之内存屏障.读写自旋锁及顺序锁 在上一篇博文中笔者讨论了关于原子操作和自旋锁的相关内容,本篇博文将继续锁机制的讨论,包括内存屏障.读写自旋锁以及顺序锁的相关内容.下面首先讨论内存屏障的相关内容. 三.内存屏障 不知读者是是否记得在笔者讨论自旋锁的禁止或使能的时候,提到过一个内存屏障函数.OK,接下来,笔者将讨论内存屏障的具体细节内容.我们首先来看下它的概念,Memory Barrier是指编译器和处理器对代码进行优化(对读写指令进行重新排序)后,导致对内存的写入操作不能

大话Linux内核中锁机制之完成量、互斥量

大话Linux内核中锁机制之完成量.互斥量 在上一篇博文中笔者分析了关于信号量.读写信号量的使用及源码实现,接下来本篇博文将讨论有关完成量和互斥量的使用和一些经典问题. 八.完成量 下面讨论完成量的内容,首先需明确完成量表示为一个执行单元需要等待另一个执行单元完成某事后方可执行,它是一种轻量级机制.事实上,它即是为了完成进程间的同步而设计的,故而仅仅提供了代替同步信号量的一种解决方法,初值被初始化为0.它在include\linux\completion.h定义. 如图8.1所示,对于执行单元A

MySQL学习笔记十六:锁机制

1.数据库锁就是为了保证数据库数据的一致性在一个共享资源被并发访问时使得数据访问顺序化的机制.MySQL数据库的锁机制比较独特,支持不同的存储引擎使用不同的锁机制. 2.MySQL使用了三种类型的锁机制,分别为:表级锁,行级锁,页级锁,它们的特性如下所示. 表级锁:实现逻辑较为简单,加锁速度快,开销小,不会发生死锁:但粒度最大,发生锁冲突的几率最大,并发度最小,适用于以查询为主,极少量更新的系统. 行级锁:加锁慢,开销大,会发生死锁:但粒度最小,锁冲突率小,并发度最高,使用于并发查询大,有大量按