Document directory
You can download the original Vim Recipes text from runpaint.
Select The Right Mode)
Problem
Although you know that Vim has multiple operation modes, you are not sure when to use them.
Solution
There are four common modes:
Insert mode)
It is only used for input, not in this mode. Minimize the time required to use this mode.
Normal mode)
Edit in this mode: Move in the file, change the text content, and rearrange the text structure. In this mode, you usually need to enter and exit the insert mode in due time.
Visual mode)
Select text in this mode to cut, copy, or format the selected text.
Command-Line mode)
In this mode, enter the command line, for example, set number.
Discussion
The Vim mode seems confusing, but it is the key to understanding Vim.
We are often tempted by the Insert mode. We spend a lot of time in the Insert mode and use the arrow keys (arrow keys) to browse the text. However, this method is slow and requires more buttons.
Normal mode is the default mode of vim, because in Normal mode, it is easier to move in the file, and the location where you want to edit or prepare to insert text is faster.
In insert mode, you can use <ctrl> + o to temporarily enter normal mode (the command is automatically returned to insert mode after one edit ). For example, in Insert mode, use <ctrl> + o gqas to enter Normal mode, format the current section, and return to Insert mode.
For example, if you want to find and override a paragraph, you can search for this paragraph in Normal mode (e.g. /Hobson argued), or to the paragraph (e.g. use <ctrl> + F to scroll down ). After finding it, you can use basic mobile commands or text objects to move the part you are interested in. Then, you can use the text object to select some text for modification. For example, use caw to delete the current word and enter the insert mode. After the task is completed, press <Esc> to return to Normal mode again.