1.VIM文本编辑器  
模式  
功能  
 
 
 
命令模式  
光标移动、复制删除  
cmd  
 
输入模式  
输入文本内容  
a  
 
末行模式  
保存退出、设置环境  
:  
 
 
 
2.命令模式  
命令  
解释  
 
 
h j k l  
左下上右  
 
方向键  
上下左右  
 
1G、nG  
n代表一个数字,去第1行或n行  
 
gg  
将光标定位到文章的顶端  
 
G  
将光标定位到文章的底端 ($定位光标到行尾,0和^定位光标到行首)  
 
x,X  
向后删除,向前删除一个字符  
 
dd , ndd  
删除1行,n是一个数字,n行 。 例子:dgg dG d$ d0 D  
 
yy,nyy  
复制1行,n行  
 
p,P  
粘贴到下一行,粘贴到上一行  
 
u  
撤销  
 
ZZ  
保存退出 按键ZZ  
 
 
 
3.插入模式  
a  
字符后进入插入模式  
 
 
i  
当前字符位置进入插入模式  
 
o  
在下一行新创建一行进入插入模式  
 
A  
在行尾进入插入模式  
 
I  
在行首进入插入模式  
 
O  
在上一行新创建一行进入插入模式  
 
s  
删除光标位置字符并进入插入模式  
 
S  
删除光标所在行并进入插入模式  
 
 
 
4.末行模式  
w  
保存  
 
 
q  
退出  
 
wq  
退出并保存  
 
q!  
强制退出  
 
x  
保存退出  
 
set nu  
设置行号  
 
set nonu  
取消行号  
 
:w /newfile  
另存为其他文件 例子:":w /man.txt"  
 
:r /newfile  
读取/newfile到本文件中 例子: ":r /etc/passwd"  
 
:! command  
vim编辑过程中,查询linux ":! ls /"  
 
: e!  
重新读取文件  
 
 
 
5.其他模式  
v、V或Ctrl+V  
可视模式  
 
 
R  
替换模式  
 
/word,?word  
/向下查找,?向上查找  
 
n,N  
定位到下一个匹配字符,定位到上一个匹配字符  
 
 
 
6.试图模式(重点)  
视图模式修改方法: 
ctrl+ v , jjj,I,  写入  
7.缩进+永久保存  
:set all         查看末行模式的帮助 
:set autoindent  保存上下缩进 
:set tabstop = 2    调整tab键缩进 
:set nu          设置行号 
 
[root@foundation0 ~] 
 
set  nu 
set  tabstop = 2  
 
[root@foundation0 ~] 
 
set  nu 
8.替换  
:s///   @@@  AAA  ; ;; 
:s/old/new/ 
:s/old/new/g 
: 
:%s/old/new/g 
: 
 
修改某一段ip地址: %s/192.168.1/172.25.250/g 
 
取消文本中某个字段::%s/10.10.10.10//g 
  
9.重定向  
1 = stand,2 = error,&= 1 + 2  
pwd 
ls  
echo  hello 
echo  $SHELL  
echo  12345  
echo  123456  > file1 
cat  file1 
grep  root /etc/passwd 
grep  root /etc/passwd > /opt/a.txt 
cat  /opt/a.txt 
grep  apache /etc/passwd 
grep  apache /etc/passwd > /opt/a.txt 
cat  a.txt 
echo  123456  
echo  123456  >> a.txt 
cat  a.txt 
echo  abcd 1 >> a.txt 
cat  a.txt 
ls  
cd  dir1 
cd  dir1 2 >  err 
cat  err 
cd  dir1 2 >  /dev/null 
find  / -user  studnet 
find  / -user  student 
find  / -user  student 2 > err 
vim  err 
find  / -user  student 2 > err > sta 
vim  sta 
find  / -user  student &> share 
vim  share 
grep  na /etc/resolv.conf 
vim  /etc/resolv.conf 
grep  ^$  /etc/resolv.conf 
cat  -n  /etc/resolv.conf 
cat  -n  /etc/resolv.conf  | grep  ^$  
cat  -n  /etc/resolv.conf 
vim  ~/.vimrc 
cat  -n  /etc/resolv.conf 
cat   /etc/resolv.conf 
grep  -n  ^$  /etc/resolv.conf 
grep  na /etc/resolv.conf 
ls  /root/ 
ls  
grep  na /etc/resolv.conf 
grep  na /etc/resolv.conf   > /root/lines.txt 
cat  /root/lines.txt 
history -w  
tc/resolv.conf   > /root/lines.txt 
cat  /root/lines.txt