进入编辑模式

1、[root@test ~]# vi /etc/services 

2、输入小写的i后再下发就会出现--INSERT--,就可以编辑

#

# Each line describes one service, and is of the form:

#

# service-name  port/protocol  [aliases ...]   [# comment]


-- INSERT --


3、可以在光标下新增一行,用小写的o


vim命令模式

1、查找

/even

# Each line describes one service, and is of the form:


# service-name  port/protocol  [aliases ...]   [# comment]

/even


2、按n选择下一个(向下查找)

3、输入?even 选择n向前查找

4、将所有的even字符替换成test,若是不加g的话,就只替换第一行

:1,$s/enev/test/g

5、:1,955s/zserv/test/g,在1行到955行替换


vim实践

1、[root@test ~]# cp /etc/services /temp/1.txt

2、需要查看45行

:45

3、删除一行

dd

     删除3行

3dd

4、还原上一步

u

5、移动到最后一行

G

6、移动到行首

gg

7、复制2行

2yy

8、粘贴

p

9、按u恢复上一步,按Ctrl+r 相反