Basic Vim Commands - Getting Started
Start learning to use Vim. Get started with some simple commands.
Vim has two modes.
1. Insert mode (You can type like a normal text editor. Press i to insert mode)
2. Command mode (you issue commands to the editor to complete a task. Press ESC to enter command mode)
Most of the following are in command mode
Order | illustrate |
---|---|
x | Remove unnecessary characters |
u | Undo the last command, U undo the entire line |
CTRL-R | redo |
A | Append text at the end |
:wq | Save and exit |
:q! | Discard all changes and force quit |
dw | Move the cursor to the beginning of a word to delete it |
2w | Move the cursor forward two words. |
3e | Move the cursor forward to the end of the third word. |
0 (zero) | Move to the beginning of the line. |
d2w | Remove 2 words...the number can be changed to remove the number of consecutive words like d3w |
dd | Delete row |
The format of the change command is: operator [number] movement
-运算符-是该做什么,例如删除d
- [数字] - 是重复动议的可选计数
-运动-在要操作的文本上移动,例如w(单词),$(到行尾)等。
Order | illustrate |
---|---|
p | Place previously deleted text behind the cursor (type dd to delete the line and store it in a Vim register. Type p to place the line) |
r | Replace letters, for example press re to replace letters with e |
ce | Change to the end of the word (put your cursor over the u in lubw and it will delete ubw) |
ce | Removes the word and puts you in insert mode |
G | Move to the bottom of the file. |
gg | Move to the beginning of the file. Type the line number you are using and then type G |
% | Find matches), ], or } |
: s/old/new/g | Replace 'old' with 'new' where g is global |
/ | Search backward, N to find next, N to search in opposite direction |
? | forward search |
:! | Run a shell command, for example: ! dir,:! ls |
:in TEST | (Where TEST is the file name of your choice.) Save the file |
v | Start visual mode to select rows and you can perform actions like delete |
:r | filename will insert the contents into the current file |
R | Replace multiple characters |
y | Operator uses v visual mode to copy text and p to paste text |
o | Open a row under the cursor and start insert mode. |
O | Opens a line above the cursor. |
a | Insert text after the cursor. |
A | Insert text after the end of the line. |
e | The command moves to the end of the word. |
y[n]w | Copy one (n) word. |
y[n]l | Copy 1(n) characters to the right of the cursor. |
y[n]h | Copy 1(n) characters to the left of the cursor. |
R | Enter replacement mode until pressed. |
ctrl-w | Jump from one window to another |
:e | Then press ctrl+D to list all command names starting with:e, then press tab to complete the command |