记得刚工作接触linux的时候,首先要学的就是如何编辑文件,那么vim编辑工具就来了。
vi file文件名,打开文件。如无该文件,则创建该文件。
:q — 离开vi编辑器
a or i –进入编辑模式
:w –存档
:wq –存档并退出vi
vi三种模式
1)command mode 最下方有提示信息,或者是空白的。可移动光标、删除、复制、剪贴
2)insert mode 按A键可进入insert mode,退出到command,按ESC键。
3)extend mode 从command mode按冒号(:)进入.离开、存档、搜索关键词时用该模式。
command mode下,光标移动的控制键,
h 左
j 下
k 上
l 右(方向键也可)
w 到前一个单词
b 回退一个单词。
( 往下一个句子
) 回退一个句子
{ 往下一个段落
} 回退一个段落
进入insert模式
a append after the cursor(光标)
i insert before the cursor
————————————————
A append to end of line
I insert beginning of line
————————————————
o open a line below(在光标所在行的下面新增一行空白)
O open a line above(在光标所在行的上面新增一行空白)
command mode下的change、delete and Yank(copy)
change delete Yank(copy)
—————————————————————-
Line cc dd yy
Letter cl dl yl
Word cw dw yw
—————————————————————-
p / P 粘贴命令
用来粘贴以上changed、deleted、copied的内容。
1)For line oriented data:
p(小写) 粘贴数据到当前行的下面
P(大写) 粘贴数据到当前行的上面
2)For charater oriented data:
p(小写) 粘贴数据到当前光标的后面
P(大写) 粘贴数据到当前光标的前面
Undoing Changes:command mode
u undo most recent change
U undo all changes to the current line
Searching for Text:command mode
/text search downwards for “text”
?text search upwards for “text”
——————————————–
n continue search in the same direction
N continue search in the opposite direction
command mode 小技巧
dtC 从光标处到C之间的字符删除
rC 用C取代光标所在的字符
x 删除光标所在的字符
5dd 删除5行
5yy 复制5行
5x 删除5个字符
R 逐个字符的替代,取消按<——,直到按下ESC退出
——————-033-08 00:35:04————
存档和退出:
:w saving
:q quit
:wq save and quit
! 强制保存/退出,如::w!强制存档,:q!强制退出,:wq!强制存档并退
出。