马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
#--------------------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 |