vim编辑文件,进程意外中断,编辑的文件如何恢复

《开经偈》
无上甚深微妙法
百千万劫难遭遇
我今见闻得受持

愿解如来真实义


使用vim命令打开一个已经创建好的文件

[root@localhost vitest]# vim file.txt

进入一般态,点击i,进入编辑态,在编辑态中输入hello world。

按下ESC,进入一般态。然后按下Ctrl + Z,将当前编辑文件的线程隐藏到后台执行,但是线程并没有退出。

此时回到命令态。在命令态输入kill -9 %1,杀死在后台运行的编辑线程。注意,此时file.txt中编辑的文件并没有保存。

可是hello word很重要。你必须要将它恢复过来。怎么做?


step1:

在当前目录下输入 ls -al,你会发现

[root@localhost vitest]# ls -al
总用量 40
drwxr-xr-x. 2 root root  4096 5月  12 00:44 .
drwxrwxrwt. 4 root root  4096 5月  12 00:04 ..
-rw-r--r--. 1 root root     0 5月  12 00:35 file.txt
-rw-r--r--. 1 root root 12288 5月  12 00:45 .file.txt.swp
-rw-r--r--. 1 root root    64 5月  12 00:10 man.config
-rw-r--r--. 1 root root 12288 5月  12 00:06 .man.config.swp

-rw-r--r--. 1 root root     1 5月  12 00:42 vifile.txt

注意file.txt.swp文件是file.txt文件的缓存。它就是你恢复文件的根本。

此时我们打开file.txt,


    点击R就可以恢复,hello world重现。现在的问题是你每次打开file.txt时,都出弹出提醒框,咋办?为什么每次都会弹出?因为file.txt.swp的存在,将它删除就可以。

[root@localhost vitest]# ls -al
总用量 44
drwxr-xr-x. 2 root root  4096 5月  12 01:03 .
drwxrwxrwt. 4 root root  4096 5月  12 00:04 ..
-rw-r--r--. 1 root root    12 5月  12 01:03 file.txt
-rw-r--r--. 1 root root 12288 5月  12 00:45 .file.txt.swp
-rw-r--r--. 1 root root    64 5月  12 00:10 man.config
-rw-r--r--. 1 root root 12288 5月  12 00:06 .man.config.swp
-rw-r--r--. 1 root root     1 5月  12 00:42 vifile.txt
[root@localhost vitest]# rm -f .file.txt.swp
[root@localhost vitest]# ls -al
总用量 32
drwxr-xr-x. 2 root root  4096 5月  12 01:03 .
drwxrwxrwt. 4 root root  4096 5月  12 00:04 ..
-rw-r--r--. 1 root root    12 5月  12 01:03 file.txt
-rw-r--r--. 1 root root    64 5月  12 00:10 man.config
-rw-r--r--. 1 root root 12288 5月  12 00:06 .man.config.swp
-rw-r--r--. 1 root root     1 5月  12 00:42 vifile.txt

猜你喜欢

转载自blog.csdn.net/qq_23143555/article/details/80283712