如果vi打开一个文件,但又去做其他事而不及时把它关掉,等再回来处理时,ESC键已经失效,这时可以按Ctrl+z强制退出(或者直接关闭终端窗口)。但再次用vi打开此文件时,就会出现以下内容:
E325: ATTENTION
Found a swap file by the name “.Makefile.swp”
owned by: yuanyuanchen dated: Mon May 24 15:10:26 2021
file name: ~yuanyuanchen/Documents/BinaryAsteroid/asteroid_binary-main/myexamples/bin2/Makefile
modified: no
user name: yuanyuanchen host name: Yuanyuans-MacBook-Pro.local
process ID: 4180 (still running)
While opening file “Makefile”
dated: Mon May 24 14:31:58 2021
(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 Makefile”
to recover the changes (see “:help recovery”).
If you did this already, delete the swap file “.Makefile.swp”
to avoid this message.
Swap file “.Makefile.swp” already exists!
[O]pen Read-Only, (E)dit anyway, ®ecover, (Q)uit, (A)bort:
这时可以按E进入文件正常编辑。但以后每次vi打开此文件时都会有这一步,是不是很烦???
怎么再恢复正常的vi打开方式呢?到底发生了什么?
其实上面这堆英文里已经给出答案啦~~
因为在强制退出后,有个隐形文件.Makefile.swp被创建(这里的Makefile对应刚才vi打开的文件名,可能是其他的名字),所以只要删除.Makefile.swp就可以了!
返回含这个文件的目录,输入rm .Makefile.swp即可。这里的Makefile要改成你自己的文件名。