回复关键字【资料】获取各种学习资料
4、vim从命令模式切换到编辑模式
a:从光标后面开始插入 大a:行尾插入
i:与a相对应,从光标前开始插入 大i:行首插入
o:在当前光标下面另起一行开始插入 大o:上面另起一行开始插入
s:吃掉当前光标覆盖的字符,然后开始插入 大s:吃掉一行,开始插入
5、vim的末行模式
使用esc退出编辑模式
使用:进入末行模式
在末行模式下,直接输入数字,回跳转到对应行号
wq:保存并退出
q:退出,如果做了修改,提示是否保存,如果没作修改,会直接退出
q!:退出不保存
w:保存不退出
x:功能相当于wq,保存并退出
在命令模式中也有一个退出并保存命令:shift + zz,但他跟wq是有区别的
wq会创建出新文件,shift + zz并不会,因此可以直接使用vi来创建新文件而不用touch命令
eg:
vi test wq退出并保存,当前目录下会有一个新文件test,使用shift + zz是没有这样的效果的
末行模式下的替换操作
26 mike is a chinese, mike is from china, china is a beautiful countroy!!!
27 mike is a chinese, mike is from china, china is a beautiful countroy!!!
28 mike is a chinese, mike is from china, china is a beautiful countroy!!!
29 mike is a chinese, mike is from china, china is a beautiful countroy!!!
30 mike is a chinese, mike is from china, china is a beautiful countroy!!!
31 mike is a chinese, mike is from china, china is a beautiful countroy!!!
32 mike is a chinese, mike is from china, china is a beautiful countroy!!!
33 mike is a chinese, mike is from china, china is a beautiful countroy!!!
34 mike is a chinese, mike is from china, china is a beautiful countroy!!!
35 mike is a chinese, mike is from china, china is a beautiful countroy!!!
36 mike is a chinese, mike is from china, china is a beautiful countroy!!!
可以使用末行模式的替换操作,将上面的mike替换为指定的字符串
本例中替换为heqile
格式:s/old/new/(g[c])
后面的参数g是不询问直接进行替换,如果参数是gc,则在替换时会进行询问
eg:
第27行中的mike替换为heqile:
先将光标置于第27行,然后进入末行模式
s/mike/heqile
第27行中所有的mike都替换为heqile:
先将光标置于第27行,然后进入末行模式
s/mike/heqile/g
范围替换,将26行至36行中的mike全部替换为heqile
26,36s/mike/heqile/g
替换本文当中所有选定字符串为指定的新字符串(使用通配符%)
%s/mike/heqile/g
vim的分屏
sp:水平分屏
vsp:垂直分屏
ctrl + ww:切换屏幕
qall:退出当前的所有屏幕
vsp 当前目录下的另一个文档:可以垂直分屏方式打开另一个文件
在打开时就分屏显示:
vi -o test1.cpp test2.cpp 小o代表水平分屏
vi -O test1.cpp test2.cpp 大o代表水平分屏