Vim的执行过程
1、当vim打开一个文件时会在当前目录下生成一个以 点swp为结尾的隐藏文件(修改文件其实就是修改了隐藏文件)
2、打开文件进入命令模式然后到末行模式进行退出
3、系统会根据是否改变了文件内容,如果改变了文件,隐藏文件会覆盖源文件,删除隐藏文件,如果没有改变,会直接删除隐藏文件。
Vim的执行故障
当用vim打开一个文件时,会出现以下报错:
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:
原因:
1、有人正在编辑这个文件
2、非正常退出导致的
排除:
1、先确定有没有人正在编辑这个文件
2、vim -r 打开这个文件,恢复之前没有保存的状态,然后保存退出,之后再执行rm -rf 删除隐藏的临时文件就OK了。