:q! quit and not save
:wq save and quit.
:e FileName edit the specific file.
:w filename save as filename
:r Filename read a file and insert it to current place.
:r !ls can read the input of ls command and insert them into current place.
h j k l move left up down right
0 move to the begin of a line.
$ move to the end of a line.
e move to the end of a word.
w move to the begin of second word
2e, 2w move to the end/begain of the second word.
C^g show the current line number of the file.
gg move to the start of the file
G move to the bottom of the file
number G go to the specific line
% move to the matching (, ], or }
i insert to current place.
a insert to next character.
A insert to the end of this line.
o open a new line bellow,
O open a new line above.
x delete unwanted character, and then into the text editing mode.
c[number]w/e/$ cut current several word or line form current place
d[number]w/e/$/d to delete. dw word, de, to the end of the current word, d$ to the end of the line, dd, the whole line. Numbers can be used to delete several, d2w,d2d
r replace the current character with typed key. such as r6 will replace current character by 6.
R replace more than one charactors.
u undo previous action, U, undo all the changes on a line, C^R, to undo the undo's.
v select part of the files
y copy the selected text by v
p paste the cut or copyed text to current place.
:w filename write the selected text to a file
1, :/ :? search forward or backward,
n, N, when searching, n search again, N search again but the opposite derection
C^o, go back before n used,
C^i, go foreward
2, :s/old/new/g , to replace old to new, g means all in that line
:#,#s/old/new/g, #,# are 2 line number.
:%s/old/new/g , to change every occurrence in the whole file.
:%s/old/new/gc, to find every occurrence in the whole file, with a prompt whether to substitute or not.
1, :! execute an external command.
:set ic ,means ignore case when searching, which is the same as :/keyword\c.
:set noic, disable ignoring case.
:set hls is, set the hlsearch and incsearch options.
2, :help open the help window,
3, make sure vim is not in compatible mode :set nocp
type the beginning of the command, such as :e
C^d will shows all the vim command start by e, and <tab> will complete the name.
4, vim has many more features than vi, but they are disabled by default. These featrues are specified by the ~/.vimrc. There is an example file $VIMRUNTIME/vimrc_example.vim