- The four modes of VIM skills _ Normal Mode
- A common pattern of not loving
- Tough operation under normal mode
- What is an operator
- What is an action command?
- How to do wrong operation
- That kind of operation is more cost effective
- Mysterious strokes in normal mode
The four modes of VIM skills _ Normal Mode
As we all know, thevimmost distinctive thing in it is that it can switch patterns, what is the pattern? It is easy to understand that you can get different effects by pressing the same key under different modes. For example,Vimif you press two times under Insert moded, two letters will be inserted at the cursor positiond, and if you press two times under normal mode, thedcurrent row of the cursor will be deleted.
SinceVimthe four models are said,Vimwhat are the four models?
- Normal mode
- Insert mode
- Visual mode
- Command-line mode
The user can<ESC>toggle between the modes by pressing, below we will introduce the Normal mode in detail, other modes we will introduce in detail in the following article
A common pattern of not loving
LikeEmacs,Sublime TextThese mainstream editors can enter their own content directly after opening, but forVimthe first-time novice, it's not the same as what he imagined, Daoteng will start to freak out for a while:
- How to enter text in this box?
- God, how to quit this black box??!!! (Bloggers started off with kill-9, crying)
VimThe default is to use Normal mode when it is turned on, as shown in
If you need to enter something in this black box, you can press any of the following keys on the screen to enterViminsert mode , then you can enter the text.
Key |
function |
A |
Insert after cursor |
A |
Inserts at the end of the line at which the cursor is currently |
I |
From the cursor where the insertion |
I |
Inserts at the beginning of the current cursor |
O |
Create a new row below the current line and insert it |
O |
Creates a new row above the current line and inserts it |
What if you exit the Normal mode between insert mode and back? Just press<ESC>it, you can.
At this point you may ask, is it possible to have an insert mode? Why do you want to add a normal mode? You see there are not so many modes in other editors ... This is the refinement of vim, for other editors, if you want to achieve a more complex operation, basically all through<Ctrl>,<Alt>,<Shilt>combined to complete, butVimnot so,Vimby switching between different modes to achieve complex operations, In short, the normal mode is used to launch skills! The insert mode is a simple text operation
For example, you need to delete the current cursor row, for a non-modal editor is the way to start this skill
<CTRL-K>(Emacs)
<CTRL-L><Backspace>(Sublime Text)
If it isVim, then first enter Normal mode and then start the skill of deleting the line
<ESC>(go to normal mode),dd(delete the current line)
Individual or more like aVimlittle, concise and clear, before also triedCtrlto dieEmacs, the combination of buttons is really many, and the hands of small people is simply a kind of torture!
Tough operation under normal mode
Normal mode The following action can be interpreted as the following formula:
Damnmadecharacter+MovingmadeLifemake=Damnmade
What is an operator?
operator is what are you going to do next? For example, the above mentioneddis the delete operator, in addition to deleting the operator, there are the following operators:
operator |
Use |
C |
Modify |
D |
Delete |
Y |
Copy |
g~ |
Case reversal |
Gu |
Convert to lowercase |
GU |
Convert to uppercase |
> |
Indent Right |
< |
Chanzo Indent |
= |
Auto Indent |
What is an action command?
Operator is used to specify an operation, this operation can not be blind operation? I want to delete a line of text, not the entire contents of the whole file to delete it ... So, simply put, an action command is used to specify the scope of the operator's function.
What about the action orders? In fact, the action command is more flexible, here I summed up there are two categories:
- A type of text object, such as AW, AP
- One type is the position range, such as L, j,k,f{char},$,^,0 ...
Action commands for text object types
Text Object |
Operating Range |
Aw |
Add a space to the word where the cursor is located |
Iw |
The word where the cursor is |
Ap |
The paragraph where the cursor is |
i< |
<>The text inside |
i{ |
{}The text inside |
I |
""The text inside |
Suppose you now have such a line of text
I am a Vimer
We need to deleteVimerthis word
$(move to end of line)
daw(Delete the word with the cursor and a space)
Finally get:
I am A
action commands for position range types
What is the position range? Is the text that starts at the current cursor, passes through a new cursor position after a move command, such as,,, and so3j10<Space>3lf{char}on, as long as the command that can move the cursor can
Suppose you now have such a line of text
I am a Vimer
We're going toVimerecapitalize all the text between this word subtitle.
0(move to the beginning of the line)
gUte(operator (GU) + (new cursor position TE))
Finally get:
I AM A Vimer
Note One thing:
When an operator is called twice in a row, the corresponding scope is the current row, for example, to delete the current row, or to copy the current rowddyy,gUgUor to capitalize the current row.
How to do wrong operation?
We can switch to normal mode, and then weucan undo the previous error, such as the deletion ofdda line of text by mistake, weucan directly input to undo the previous delete operation
Now let's look at a chestnut:
Enter a line of text
I am a Vimer
found that the Vimer mistakenly lost to Vier, so return to the normal mode, clickuwant to undo the wrong word input, but surprised to find the text entered before theI am amissing,Vimtoo many undo!!
What should I do then? How do you controlVimthe size of the undo?
uKey triggers the Undo command, which undoes the most recent modification. One modification can be any action that alters text within a document, including commands triggered in normal mode, visual mode, and command-line mode, and one modification includes text that is entered or deleted in one insert mode, that is, ai{insert some stuff}<ESC>modification
So we can still control theusize of the undo, in the insert mode, every time<ESC>even a granularity of control
That kind of operation is more cost-effective?
What's a bargain? That means more text operations with minimal keystrokes.
Give me a chestnut:
Now you need to delete the last word from the following text
I am a Vimer
Operation One:
$
DB (delete word forward)
X (delete x)
Operation Two:
$
B (the first word of the last word)
DW (delete word)
Operation Three:
$
Daw
The above three operations are all using the same number of keys, this step on everyone to play a tie, if we still have to delete the remaining two words? The first two operations obviously need to be repeated from the beginning, but the third operation we only need to use.the operation can be repeated to modify the command, so operation three obviously more cost-effective! So a broader definition of cost-effective is not only the current operation, but also the future operation to be counted in.
Mysterious strokes in normal mode
This mysterious trick is actually
- <C-a>: Adding numbers to the operation
- <C-x>: Reduce the number of operations
<C-a>The command adds 1 above or above the current cursor, if necessary, so that the number is added to the[count]<C-a>count
Give me a chestnut:
Existing text:
I am years old
Now it needs to be23changed24, if now you don't know this technique, then only
f3(Move to3)
r4(will be3replaced4)
It's too tedious.
Now all we need is
<Ctrl-a>(the cursor jumps immediately to the23top, and the value is added1, and becomes24)
If you need to23change it now1023(thousand old demon)
only need
1000<Ctrl-a>
The same can be done<C-x>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The four modes of VIM skills _ Normal Mode