Under CentOS7 common vim editing skills

Describes common vim preparation skills

There are three modes need to distinguish between vim and note insert mode, edit mode, command line mode
ps (vim first is to enter the edit mode can be compiled directly with the command, such as copy and paste the contents of what)

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

(A) The following command skills were all carried out in the edit mode

1, Jump

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

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

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

    G                       跳转文件末行首字符处

Can this in mind:

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

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

2, copy / paste / revocation

yy copy cursor at row

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

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

    x                    删除光标处的单个字符

    dd                  删除光标处的一行

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

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

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

    u                    撤销上一次操作

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

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

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

3, find the keyword / Save

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

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

        ZZ                 保存修改并退出

(Ii) below in the command mode, the keyboard is in edit mode: and enter the command

1, read the contents of other files to the cursor line

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

2, the replacement string

        :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, line numbers

: Set nu show line numbers

: Set nonu turn off the display

At last

: Wq to save and exit

 :q!                       强制退出,不保存

Reprinted from: https://www.centoschina.cn/course/introduction/10283.html

Guess you like

Origin www.cnblogs.com/7haoyu/p/11266199.html