gvim 常用命令整理

Vim是从vi发展出来的一个文本编辑器。代码补完、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。和Emacs并列成为类Unix系统用户最喜欢的编辑器

# ------ summary : FR--------------------------------
vi is an powerful file editor for programming in Linux OS.
vim       : vi improved
gvim      : GUI of vi 
two mode  : editing and command mode
.vim      : highligh word file
.vimrc    : configuration file of VI

# ------ file operation : FR-------------------------

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

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

:i     : go to insert mode 
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 : FR----------------------------
->/<-     : left/right/up/down 
h|j|k|l   : h(left)| j(down) | k(up) l (right)
          : 3h | 4j | 5k | 6l
:w        : move forward one word eg. 3w
:b        : move backward one word eg. 4b
:$        : move to the end of a 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
: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: FR -------------------

d=delete, y=copy, p=paste

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

:yy       : copy a line et. 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
:.        : repeat last operation 
😡        : delete a character eg. 3x

# ------ undo the editing : FR ------------------------------
:u|U      : undo
:CTRL+R   : need the modification

# ------ insert cursor : FR ---------------------------------
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  : FR ---------------------------------------
:/pattern : go to the pattern
          : n|N
:?pattern :
SHIFT + * : match the word marked cursor
:number_line : go to the number line

# ----- replace : FR -----------------------------------------
: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
:10,23s/x/y/g : 

# ----- special operation : FR -------------------------------
:sp       : splite horizontally ; put some files into one terminal
CRTL + WW : change file in splite command
:ZZ|q     : quit a splite file

:set diff : compare two files
:vsp      : visual splite vertically
CRTL + WW : 

CRTL + V  : visual mode
          : d|D , y|Y, r | R 
shift + i : input 
          
gf        : go into file
CRTL + O  : return the original file 

# ------ other command : FR ----------------------------------
:.    	  : repeat last operation
:J        : Merge the under line and the current line eg. 3JA
:r        : replace
:~        : change case-sensitive character 

# ----- keyword complenment : FR ----------------------------
ctrl + n
Tab

# ----- % auto match the (),{},[] : FR ----------------------
%

# ----- go into shell : FR ----------------------------------
:sh

# ---- run shell command : FR -------------------------------
:!cmd