vim错误的打开姿势

1.vim非正常退出导致的

#文件未正常退出,当前shell连接中断导致以下问题

[root@whb ~]# vim passwd 
E325: ATTENTION
Found a swap file by the name ".passwd.swp"
          owned by: root   dated: Wed Dec 11 14:51:24 2019
         file name: ~root/passwd
          modified: YES
         user name: root   host name: whb
        process ID: 106673         ##程序产生的PID,但在系统进程中查找到
While opening file "passwd"
             dated: Wed Dec 11 14:31:02 2019

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

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

[root@whb ~]# ll -a | grep passwd
-rw-r--r--   1 root root     5481 Dec 11 14:31 passwd
-rw-r--r--   1 root root    20480 Dec 11 14:51 .passwd.swp
[root@whb ~]# ps aux | grep vim
root     130156  0.0  0.0 112708   972 pts/2    R+   14:52   0:00 grep --color=auto vim

#如果你想恢复之前在文件中已经修改但未保存的操作
[root@whb ~]# vim -r passwd       #会提示你,回车即可
[root@whb ~]# ll -a | grep passwd
-rw-r--r--   1 root root     7348 Dec 11 14:58 passwd
-rw-r--r--   1 root root    20480 Dec 11 14:51 .passwd.swp
[root@whb ~]# rm -rf .passwd.swp    #删除隐藏的.passwd.swp文件
[root@whb ~]# ll -a | grep passwd     
-rw-r--r--   1 root root     7348 Dec 11 14:58 passwd

2.别人正在编辑这个文件时,你打开此文件

[root@whb ~]# vim passwd
E325: ATTENTION
Found a swap file by the name ".passwd.swp"
          owned by: root   dated: Wed Dec 11 19:45:20 2019
         file name: ~root/passwd
          modified: no
         user name: root   host name: qls
        process ID: 68044 (still running)
While opening file "passwd"
             dated: Wed Dec 11 18:32:03 2019

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

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




[root@whb ~]# vim  -r  passwd 		#恢复之前没有保存的状态
[root@whb ~]# vim  passwd 
[root@whb ~]# rm -f .passwd.swp 	#删除临时文件

[root@whb ~]# ps  aux | grep  vim		#查看后台vim进程

root      68044  0.0  0.2 149224  5092 pts/2    S+   19:45   0:00 vim passwd
root      68148  0.0  0.0 112708   976 pts/1    R+   19:47   0:00 grep --color=auto vim

 

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注