CentOS7--常见的vim编辑技巧

本文介绍了 Vim 文本编辑器的使用技巧,包括不同模式间的切换、文本操作如复制粘贴、撤销等基本命令,以及查找和替换字符串的方法。同时提供了如何在 Vim 中读取其他文件内容和设置行号等高级技巧。

介绍常见的vim编制技巧

vim有三个模式需要区分和注意,插入模式编辑模式命令行模式

     ps(进入vim首先就是编辑模式可以可以直接用命令编制内容比如复制粘贴什么的)

         (编辑模式下按键盘  :  键 然后可以进入命令模式就可以在 : 后打相关命令了)

         (编辑模式下按 i 或者o  可进入插入模式)


(一)下面进行的命令技巧全是在编辑模式下进行的

    1、跳转

        Home键        跳转至当前光标所在行的首字符处

        End键            跳转至当前光标所在行的末尾字符处

        gg                    跳转文件的首行首字符出这个跟光标的位置没关系

        G                       跳转文件末行首字符处


        可以这样记 :

            Home键和End键是对立的,一个是跳转当前鼠标首字符处,一个是当前鼠标末字符处

            gg和G是对立的,一个是跳转首行首字符,一个是末行首字符


     2、复制/粘贴/撤销

        yy                   复制光标处的一行

        p                     粘贴 yy 刚复制的那行粘贴在光标所在的下一行

        yy  p    是一对组合,很好用用的多很好记住很好记住


        x                    删除光标处的单个字符

        dd                  删除光标处的一行

        d^                  从光标处删除至当前行的行首

        d$                  从光标删除至当前行的行尾  

        C    (大写)    从光标处删除至当前行的行尾,并进入输入模式,跟 d$  一样只是他可以删除了不要 i 进入输入,直接可以输入

        u                    撤销上一次操作

        U                    撤销对当前行的所有修改

        Ctrl + r            撤销前一次的所有操作

        各种删除技巧,让你欲罢不能,手残删错了怎么办?   没关系,u 来撤销你的操作,跟Ctrl+z  一样好用,谁用谁知道


      3、查找关键字/保存

            /hello          查找文本中所有hello 字符并已黄色标出

            n、N            跳转查找结果的前一个、后一个

            ZZ                 保存修改并退出

               

(二)下面在命令模式下进行,在编辑模式下需要按键盘的  :  然后输入命令

    1、读取其他文件的内容到光标所在行

              :r  /opt/test.txt            读取    /opt/test.txt文件内容到当前光标所在行


    2、字符串的替换

            :s  /123/abc                        替换光标所在行第一个的  123  字符串改为 abc

            :s  /123/abc/g                    替换光标所在行的所有  123  字符串改为  abc

            :s  n,ms   /123/abc/g        替换n-m行所有的  123  字符串改为  abc

            :%s   /123/abc                    替换文件内所有的 123  字符串改为  abc


     3、显示行号

            :set    nu                显示行号

            :set    nonu            关闭显示

        最后

            :wq                    保存并退出

            :q!                       强制退出,不保存

     

                        

[root@iZ2zeddv2x94139qgzr55aZ /]# sudo yum clean all && sudo yum makecache 已加载插件:fastestmirror Repository centos-sclo-rh is listed more than once in the configuration Repository centos-sclo-sclo is listed more than once in the configuration 正在清理软件源: base centos-sclo-rh centos-sclo-sclo docker-ce-stable epel extras updates Cleaning up list of fastest mirrors Other repos take up 1.6 M of disk space (use --verbose for details) 已加载插件:fastestmirror Repository centos-sclo-rh is listed more than once in the configuration Repository centos-sclo-sclo is listed more than once in the configuration Determining fastest mirrors base | 3.6 kB 00:00:00 http://mirror.centos.org/centos/7/sclo/aarch64/rh/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found 正在尝试其它镜像。 To address this issue please refer to the below wiki article https://wiki.centos.org/yum-errors If above article doesn't help to resolve this issue please use https://bugs.centos.org/. One of the configured repositories failed (CentOS-7 - SCLo rh), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=centos-sclo-rh ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable centos-sclo-rh or subscription-manager repos --disable=centos-sclo-rh 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=centos-sclo-rh.skip_if_unavailable=true failure: repodata/repomd.xml from centos-sclo-rh: [Errno 256] No more mirrors to try. http://mirror.centos.org/centos/7/sclo/aarch64/rh/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值