200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > linux中vim的保存退出命令

linux中vim的保存退出命令

时间:2023-05-28 03:25:27

相关推荐

linux中vim的保存退出命令

使用vim命令打开一个文件:

例如,打开openwrt系统下的system配置文件

vim /etc/config/system

内容如下:

config systemoption hostname 'OpenWrt'option timezone 'UTC'option ttylogin '0'option log_size '64'option urandom_seed '0'config timeserver 'ntp'option enabled '1'option enable_server '0'list server '0.openwrt.'list server '1.openwrt.'list server '2.openwrt.'list server '3.openwrt.'

如果想要编辑该文件

按i键或者a键进入插入模式,这个时候左下角显示–INSERT–

编辑完成之后

按Esc键退出到命令模式

然后进入保存或者不保存的退出操作:

:w ---- 保存,不退出

:w! ---- 强制保存,不退出

:wq ---- 保存,退出(或者是:x)

:wq! ---- 强制保存,退出

:q ---- 不保存,退出

:q! ---- 不保存,强制退出

:e! ---- 放弃所有修改,从上次保存文件开始再编辑命令历史

如果是非正常关闭编辑器

再次vim该文件的时候会出现以下情形:

E325: ATTENTIONFound a swap file by the name ".system.swp"owned by: root dated: Sun Apr 25 06:33:37 file name: /etc/config/systemmodified: nouser name: root host name: OpenWrtprocess ID: 16987 (STILL RUNNING)While opening file "system"dated: Fri Apr 16 09:17:19 (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 samefile 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 system"to recover the changes (see ":help recovery").If you did this already, delete the swap file ".system.swp"to avoid this message.Swap file ".system.swp" already exists![O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

这是因为非正常关闭编辑器会生成一个.swp的文件

可以直接删除该文件

首先使用ll -a命令查看该文件

root@OpenWrt:/etc/config# ll -adrwxr-xr-x 2 100610064096 Apr 25 06:48 ./drwxr-xr-x 36 100610064096 Apr 23 03:17 ../-rw------- 1 rootroot 12288 Apr 25 06:33 .system.swp

然后使用rm -rf删除该文件

root@OpenWrt:/etc/config# rm -rf .system.swp

再次vim该文件,就正常了

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。