前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux vim命令保存退出_vim退出命令

linux vim命令保存退出_vim退出命令

作者头像
全栈程序员站长
发布2022-09-23 11:41:52
22.5K0
发布2022-09-23 11:41:52
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

使用vim命令打开一个文件: 例如,打开openwrt系统下的system配置文件

代码语言:javascript
复制
vim /etc/config/system

内容如下:

代码语言:javascript
复制
config system
        option 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.pool.ntp.org'
        list server '1.openwrt.pool.ntp.org'
        list server '2.openwrt.pool.ntp.org'
        list server '3.openwrt.pool.ntp.org'

如果想要编辑该文件 按i键或者a键进入插入模式,这个时候左下角显示–INSERT– 编辑完成之后 按Esc键退出到命令模式 然后进入保存或者不保存的退出操作: :w —- 保存,不退出 :w! —- 强制保存,不退出 :wq —- 保存,退出(或者是:x) :wq! —- 强制保存,退出 :q —- 不保存,退出 :q! —- 不保存,强制退出 :e! —- 放弃所有修改,从上次保存文件开始再编辑命令历史

如果是非正常关闭编辑器 再次vim该文件的时候会出现以下情形:

代码语言:javascript
复制
E325: ATTENTION
Found a swap file by the name ".system.swp"
          owned by: root   dated: Sun Apr 25 06:33:37 2021
         file name: /etc/config/system
          modified: no
         user name: root   host name: OpenWrt
        process ID: 16987 (STILL RUNNING)
While opening file "system"
             dated: Fri Apr 16 09:17:19 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 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命令查看该文件

代码语言:javascript
复制
root@OpenWrt:/etc/config# ll -a
drwxr-xr-x    2 1006     1006          4096 Apr 25 06:48 ./
drwxr-xr-x   36 1006     1006          4096 Apr 23 03:17 ../
-rw-------    1 root     root         12288 Apr 25 06:33 .system.swp

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

代码语言:javascript
复制
root@OpenWrt:/etc/config# rm -rf .system.swp

再次vim该文件,就正常了

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172531.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档