After reading this article, tomorrow all in vim.


On the Internet, VIM is often described as “steep learning curve”, “high entry threshold”, and so on. As a result, many people are reluctant to enter VIM after they have a little knowledge of vim. They are afraid of affecting work efficiency or considering that input is not cost-effective compared with output.

It’s true that VIM isn’t as ready to use as any other editor, but it’s far less scary. Spend a night getting familiar with the most basic ten or so commands, and install a VIM plug-in on your common editor, such asvscodevimIdeaVimVIM is the beginning.

After reading this introductory article, spend an hour to get familiar with the operation in this article, and then go back to the place where you usually write code, put down the ordinary editor and edit it with vim. You will find that on the first day when you turn to VIM, your work efficiency does not decrease, or even slightly improves.

The door of vim is opened, and the learning curve is gentle and gentle!

Create a new text file and fill in some useless code or text. This is where you practice vim.

Use in terminalvimOpen the text file, or activate the editor’s VIM mode through the plug-in mentioned earlier and open the file.

It is strongly recommended that you operate while reading this article. The process of operation is also the process of memory. After reading this article, you have basically memorized 7788, and many commands will be available immediately.


Now, we’re in the middle of vimNormal mode

Normal mode

In normal mode, you can’t edit the text directly by typing, but you can move the cursor or execute some commands.

Normal mode is the default mode of vim, which is also the most natural and relaxed state of vim. This is the difference between vim and other editors.

As you learn more about VIM, you will gradually understand why VIM is like this.

Move Cursor

In VIM, we can use thej↑ k↓ h← l→Four keys to move the cursor.

j k lRight under the index finger, middle finger and ring finger of the right hand, you can press it without moving the palm.

hIn a position on the left of the right index finger, you may feel inconvenient when you just touch VIM, but after mastering some of the commands mentioned below in this article and some more complex operations, you will find that you need to press more than one time continuouslyhorlMost of the operations can be realized by other commands. The most used isjkTwo up and two down.

Insert mode

Press in normal modeiIt’s time to insert(iIn this paper, we propose a new pattern.

The VIM in the insert mode is similar to the ordinary editor. You can move the cursor with the arrow keys and type with the keyboard.

Learn to move the cursor and the simplest typing, you can use the most basic way of text editing.

However, the powerful functions of vim have not been revealed at the moment. The following is where VIM can efficiently edit text.

More actions to move the cursor

As mentioned earlierhjklYou can only move the cursor one character at a time, and the following operations can make the cursor jump.

b wMove to the beginning of the word before and after, representingbackward,forward one word 。

e geMove to the end of the following and preceding words respectively, representingend。

0 $Move to the beginning and end of the line, respectively.

^shift 6)And0Similar, but the first non empty character to move to the current line.

command purpose
b moveTo the current / previous wordstart
w moveTo the next wordstart
e moveGo to current / next wordending
ge moveGo to the previous wordending
0 The beginning of the line
$ End of line
<⇧ 6>
First non white space character


Let’s take a look at the deletion operation.

xYou can delete the characters under the cursor,XDelete the character in front of the cursor.

dRepresented in VIMdDelete, delete in VIM by pressingdAdd the scope to delete.

The scope of deletion can be seen in the table below.

dAdd the direction key to delete a character in the corresponding direction (up and down direction will delete a line).

By the way, enter the number first in VIM’s normal modenThen enter the command, you can execute the command n times, for exampled5jIt means to delete 5 lines down.

The above-mentioned commands to move the cursor by word and move to the end and beginning of a line can also specify the range of deletion, such asdbDelete the beginning of the cursor to the beginning of the word,d$Delete from cursor position to end of line.

Double click to delete,ddCommand to delete the entire line. Similarly, you can delete multiple lines at a time by adding numbers and commands.

In addition, there is adaw, delete a word, and delete n wordsd{n}w, delete multiple words.

command purpose
dh Delete previous character(d←
dl Delete a character (equivalent tox or d→
d5j Delete 5 lines
db Delete the beginning of the cursor to the beginning of the word
d$ Delete from cursor position to end of line
dd Delete 1 line
{n}dd Delete n rows
daw Delete a word
d{n}w Delete n words

The pattern enters the insertion mode

As mentioned earlieriJust simply enter the insert mode at the current cursor position, and VIM provides some commands to move to the target position and insert more quickly.

arepresentativeaPpend will be added in theAfter the current cursor positionEnter insert mode.

Press in normal modeoIn the current row of the cursorNext, create a new lineAnd enter the insert mode, representingopen。

smeetingdeleteEnter the character under the current cursor and enter the insert mode.

These three commands also have matching uppercase commands to achieve similar operations.

AWill be inThe end of the current lineEnter insert mode,OIt will be in the current lineaboveCreate a new row and enter insert mode,SmeetingDelete entire lineAnd enter the insert mode.iThere’s a matchITo enter insert mode at the first non empty character of the current line.

command Enter the insertion mode position
a At presentAfter cursor
A At presentEnd of line
i At the cursor position
I At the first non empty character of the current line
o staylowernoodlesInsert new line
O stayuppernoodlesInsert new line
s Delete the character under the cursor
S Delete entire line

Undo operation

What if you accidentally delete the text that should not be deleted? In VIM,urepresentativeuTo undo the most recent operation.

Command mode

If you use it in a terminalvimCommand editing, you may often have to deal with VIM’s command mode.

Press:Enter the command mode of vim, enter the command and press enter.


Commands can also be entered multiple times at a time, such as:wq-Save and exit.

Add after order!On behalf of enforcement, e.g:q!-Quit without saving.

All in Vim!

Now that you have mastered the most basic insert, delete and undo operations, you can handle simple daily work.

In the next article, let’s introduce some advanced operations to take your VIM to the next level.