Vi & Vim in Linux
basic description about vi & vim
vi is Linux built in text editor
vim is the enhanced version to vi, can do program
three patterns by vi & vim
- normal pattern 正常模式
- can not edit in this pattern
 
 - edit pattern 编辑模式
 - cmd line pattern 命令行模式
 
operating process
Step 1
1  | vim Hello.java  | 

by this command, we go to normal pattern, from our command line

Step 2
1  | type i # 摁下i  | 
now we are in edit pattern

we can write our file here
Step 3
After editing
1  | we type esc first # 摁下esc  | 
now we leave the edit pattern and go to normal pattern now

then type
1  | :wq # write(save) and quit  | 


Step 4
if you want edit this file again
1  | vim Hello.java  | 

how to change vi & vim

shortcut key words 快捷键
under normal pattern : copy and paste
- copy current line : yy
 - paste : p
- copy 5 line below current line : 5yy 包括复制当前行
 
 - delete current line : dd
- delete 5 line below current line : 5dd 包括删除当前行
 
 
these are under normal pattern, if you are in edit pattern, it will just type yy in the file
search a word in the file
1  | /hello  | 
1  | type enter # 摁下回车开始查找  | 
1  | type n # 下一个,查到最后一个单词则回到开头  | 
set number for line
1  | : set nu # 设置行号  | 


1  | : set nonu # 取消行号  | 
go to the last line and first line
under normal pattern
1  | G # go to last line  | 
1  | gg # go to first line  | 
undo
at the normal pattern
1  | u # undo  | 
if do some editions in edit pattern, can type esc go to normal pattern, then type u to undo all the editions you did just now
move the cursor
at the normal pattern
1  | 20 shift g # move to the 20th line  | 
有可能键盘因为摁完shift后变成中文输入法,可以采取的措施是打开大写输入