This tutorial includes some basic vim commands and I hope that it will be helpful.
Moving the cursor
h
: leftj
: downk
: upl
: right
It takes time to get used to it.
Navigation
w
: move the cursor one word forward (to the first letter)b
: one word backward (also to the first letter)e
: one word forward (to the last letter)fx
: forward to the letterx
(
: to the start of the sentence)
: start of the sentence0
: start of line$
: end of line{
: start of paragraph}
: end of paragraphG
: end of filectrl+G
: to see the cursor location and file status
gg
: start of filexG
: to the numberx
line of file- typing a number before a motion repeats it that many times!
Delete
x
: delete the character at the cursordw
: delete all the characters between the cursor and the first letter of the next word- e.g. Please de
l
ete the word. (Assume the cursor is atl
) - After you press dw, the sentence becomes
Please dethe word delete
- e.g. Please de
de
: delete all the characters between the cursor and the next space- e.g. Please de
l
ete the word. (Assume the cursor is atl
) - After you press de, the sentence becomes
Please de the word delete
- e.g. Please de
d$
: delete to end of linedd
: delete whole linep
: After you delete something, press p to paste things you delete wherever you like.
Insert
a
: insert after the cursorA
: insert after the end of linei
: insert before the cursorI
: insert before the start of lineo
: insert in the next lineO
: insert in the previous line
Search
/yourSearchString + <Enter>
: search foryourSearchString
n
: to search for the same string again (press<Enter>
to exit)N
: to search for the same string again, but in opposite directionctrl+o
: to go back to where you came fromctrl+i
: to go forward- set option
:set ic
: ignore case:set noic
: disable ignore case:set hls
: highlight the matches:set nohls
: disable highlight matches:set is
: increase search:set nois
: disable increase search
%
: move the cursor to the other matching parenthesis
Replace
rx
: replace the character at cursor withx
ce
: almost the same asde
, but this time will place you in Insert Modes/old/new
: replace the first occurrence of ‘old’ with ‘new’s/old/new/g
: replace all occurrence of ‘old’ with ‘new’ in one line#,#/old/new/g
: #,# are the line numbers of the range of lines where the replace should be done%s/old/new/g
: replace all occurrence of ‘old’ with ‘new’ in the whole file%s/old/new/g
: replace all occurrence of ‘old’ with ‘new’ in the whole file, with a prompt whether to replace or not
Undo & Redo
u
: undo the last commandU
: undo the command excuting on the while linectrl+R
: redo the command
Copy & Paste
y
: to copyp
: to paste- e.g. Start Visual Mode with
v
and move the cursor to chose whatever you want, typey
to copy the highlighted text and typep
to paste the text.
- e.g. Start Visual Mode with
Others
.
: repeat the last command<start position><command><end position>
: many commands follow this pattern- e.g.
0y$
means copy the whole line0
move the cursor to the start of liney
copy$
move the cursor to the end of line
- e.g.
ctrl+n
: auto complete