#——————–Vim Basic———————————————–
#file name : vim_basic
#author : LGP
#date : 2018-07-11
#contact : lgp_0615@163.com
#——————————————————————————

#———————summary————————————————–
vi is an powerful file editor for programming in Linux OS.
vim : vi improved
gvim : GUI of vi
.vim : highlight word file (璇硶楂樹寒)
.vimrc : configuration file of VI (瀛椾綋銆佽儗鏅鑹?
two mode : editing(insert) and command mode

#——————file operation———————————————-

#——–open a file————————————-
vi file_name : open a file for editing on a terminal
vim file_name :
gvim file_name : gvim is a GUI of vi

ctrl + 6 : 涓や釜鏂囦欢涔嬮棿鍒囨崲
:bn : 涓嬩竴涓枃浠?
:bp : 涓婁竴涓枃浠?
:ls : 鎵撳崱鏂囦欢鍒楄〃
:b1-n : 鍒囨崲鑷崇n涓枃浠?

# when open a file, vi is in insert mode by default

i : go to insert mode(before cursor)
a : go to insert mode(after cursor)
s :
o : go to insert mode(next line)
esc : go to command mode
:w : write into the file (save)
:q : quit vi
:q! : force to quit and abort the modification
:wq : save and quit

#—————-move cursor ————————————

->/<- : left/right/up/down
h|j|k|l : h(left)| j(down)| k(up)| l(right)
: 3h | 4j | 5k | 6l
w : move forward on word eg. 3w
b : move backward one word eg. 4b
$ : move to the end of line
^|0 : move to the beginning of a line
#————————————

gg : go to the first line
G : go to the last line
nG : go to n line eg. 1G
:number : go to n line
:set nu : set number line
:set nonu
CTRL + G : display the current line and total numbers of lines
CTRL + U : page up
CTRL + D : page down

#———-delete copy and paste———————————
d = delete, y = copy, p = paste

dd : delete a line eg. 5dd
dw : delete a word eg. d3w
d0 : delete to beginning of line
d$ : delete to end of line

yy : copy a line eg. 5yy
yw
y0
y$
Y : copy
:5,10y : copy 5 – 10 line
:,10y : copy cursor – 10 line
:5,y : copy 5 – cursor line

p : paste
. : repeate last operation
x : delete a character eg.3x

#————undo the editing ————————————
u|U : undo | redo
CTRL + r : undo

#————-insert cursor ————————————–
a|A : after the cursor | end of a line
o|O : input one new line under the current line | up the current line
:help a

#————search ———————————————
:/pattern : go to the pattern
: n|N
:?pattern :
SHIFT + * : match the word before marked cursor
SHIFT + # : match the word after marked cursor

:number_line: go to the number line

#————-replace———————————————-
:r|R : replace
:%s/x/y/g : x change to y all of them
:s/x/y/g : x change to y on the current line
:s/x/y/ : x change to y on the current character
:10,23s/x/y/g :10 – 23 line,x change to y

#————–special operation———————————–
:sp file(tab) : split horizontally; put some files into one terminal
:vsp file : visual splite vertically
CTRL + w : change file in split command
:ZZ|q : quit a split file

:set diff : compare two files
gvimdiff file1 file2 : compare two files

CTRL + v : visual mode
: d|D, y|Y, r|R

SHIFT + i : insert mode for editing
ESC : Match visual mode

gf : go into file
CTRL + o : return the original file

#—————key completion————————————
ctrl + n
tab

#—————automatic matching parentheses——————-
%

#—————call shell command——————————–
:sh
:!cmd

#————-other command—————————————
J : merge the under line and the current line eg.3J
~ : change case-sensitive character

 

版权声明:本文为godlovepeng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/godlovepeng/p/9480782.html