Just type vimtutor to learn the basic usage of Vim.
^
k
< h l >
j
v
- Normally:
:q - Write and exit:
:xor:wq - Without saving changes:
:q! - Write with sudo:
:w !sudo tee %
- Single character:
x
- Activate insertion mode:
i - Insert from the beginning of the line:
I
- Append to this word:
a - Append to this line:
A
d motion where 'motion' is what the operator will operate on
- Delete from cursor to the start of the next word, EXCLUDING its first character:
dw - Delete from cursor to the end of the current word, INCLUDING the last character:
de - Delete from cursor th the end of line: 'd$'
number motion
- Moving to the start of the line:
0 - Moving the cursor 5 words forward:
5w - Moving the cursor to the end of the 3rd word forward:
3e
operator number motion
- Delete 2 words:
d2w
- Delete current line:
dd - Delete 2 lines from current line:
2dd
- Undo the last commands:
u - Undo a whole line:
U - Redo the commands:
CTRL-r
- Put line below current line:
p - Put line above current line:
P
- Replace current character to 'x':
rx - Replace multiple characters:
R
- Remove the rest of word and activate insert mode:
ceorcw - Remove the rest of line and activate insert mode:
c$
- Show your location in the file and the file status:
CTRL-g - Move to the bottom of the file:
G - Move to the start of the file:
gg - Move to line 233:
233G
- Search in forward direction:
/ - Search in backward direction:
? - Find next in the same direction:
n - Find next in the opposite direction:
N - To go back to where you came from:
CTRL-o - To go forward:
CTRL-i
- Find a match of ')', ']', or '}':
%
- To change the 1st occurrence of the word in the line:
:s/<old>/<new> - To change all the occurrence of the word in the line:
:s/<old>/<new>/g - To change all the occurrence of the word between line #1 and #2:
:#1,#2s/<old>/<new>/g - To change every occurence of the word in the whole file:
:%s/<old>/<new>/g - To change every occurence of the word in the whole file with a prompt:
:%s/<old>/<new>/gc
- Execute an external command:
:!<cmd>
- Write the whole file to another file:
:w <file> - Use
vto select the text you want to copy, then type:you will see:'<,'>, write to file::'<,'>w <file>
- Insert file to current file:
:r <file> - Insert from command line output:
:r !<cmd>
- Open a line below the cursor:
o - Open a line above the cursor:
O
- Copy one word:
yw - Copy from cursor to the end of the line:
y$ - Copy the whole line:
yy
- Ingore case:
:set ic - Disable ignoring case:
:set noic - 'hlsearch'(highlight) and 'incsearch'(show partial matches):
:set hls is
- Press
<HELP>or<F1>or type::help - Get help for command:
:help <cmd>
- Press
<TAB>or<CTRL-d>
- Jump to another window:
<CTRL-w>