- Do nothing!Read
NormalMode.
- InsertMode. Press I. (Chen Hao Note: you will see the "-insert-" in the lower-left corner of vim, indicating that you can insert it)
- NormalMode. Press
ESC
Key.
InsertAndNormalSwitched. Below are some commands for youNormalMode:
I→
InsertMode, press
ESC
Back
NormalMode.
X→ Delete a character of the current cursor.
: Wq→ Save disk + exit (:w
Storage,:q
Exit) (Chen Hao note: the file name can be followed after w)
Dd→ Delete the current row and save the row to the clipboard.
P→ Paste clipboard
Recommendation:
Hjkl(For strong examples, we recommend that you move the cursor, but it is not required.) → you can also use the cursor key. Note:
j
Just like the down arrow.
- : Help <command>→ Display the help of related commands. You can also enter
:help
Instead of commands. (Chen Hao Note: To exit the help, enter q)
NormalMode. In a general editor, you need to useCtrl
Key, for example:Ctrl-C
. That is to say, the Ctrl key is like a function key. After you press the Ctrl key, C is no longer a C, and it is a command or a shortcut key,In Normal mode of VIM, all keys are function keys.. You need to know this.
Ctrl-λI will write
<C-λ>
.
- :You need to enter
<enter>
Press enter, for example,-if I write:q
That is, you need to enter:q<enter>
.
Various insert Modes
A→ Insert after the cursor
- O→ Insert a new row after the current row
- O→ Insert a new row before the current row
- Cw→ Replace the character from the cursor position to the end of a word
- Simple move cursor
0→ Zero number, to the row Header
- ^→ The first line of the line is not the position of the blank character (the so-called blank character is space, tab, line feed, carriage return, etc)
- $→ To the end of the row
- G _→ The last line is not the position of the blank character.
- /Pattern→ Search
pattern
(Chen Hao Note: if multiple matches are found, press n to the next one)
- Copy/paste(Chen Hao Note: Both p and P can be used. p indicates that after the current position, P indicates that before the current position)
P→ Paste
- Yy→ Copy the current row
ddP
- Undo/Redo
U→ Undo
- <C-r>→ Redo
- Open/Save/exit/change the file(Buffer)
: E <path/to/file>→ Open a file
- : W→ Inventory
- : Saveas <path/to/file>→ Save
<path/to/file>
- : X,
ZZ
Or:wq
→ Save and exit (:x
Save only when needed. ZZ does not need to enter a colon and press Enter)
- : Q!→ Exit and do not save
:qa!
Forcibly exit all the files being edited, even if other files are changed.
- : BnAnd
:bp
→ You can open many files at the same time and use these two commands to switch to the next or previous file. (Chen Hao Note: I like to use: n to the next file)
.→ (Decimal point) The last command can be repeated
2dd→ Delete 2 rows
3 p→ Paste the text three times
100 idesu [ESC]→ Write "desu desu desu"
.→ Repeat the previous command -- 100 "desu".
3.→ Repeat "desu" three times (Note: It's not 300. You see, how clever VIM is ).
Never skip.
G→ To line N (Chen Hao Note: note that G in the command is capitalized, And I generally use: N to line N, for example, lines 137 to 137th)
- Gg→ To the first line. (Chen Hao Note: equivalent to 1G, or: 1)
- G→ To the last line.
W→ Start with the next word.
- E→ To the end of the next word.
%: The matching brackets are moved, including(
,{
,[
. (Chen Hao Note: you need to move the cursor first to brackets)
*And#
: Match the current word of the cursor, move the cursor to the next (or the previous) match the word (* is the next, # Is the previous)
<Start position> <command> <end position>
0y $Command means:
0→ First come to the line Header
- Y→ Copy from here
- $→ Copy to the last character of the row
YeFrom the current position to the last character of the word.
Y2/fooTo copy the strings between two "foo.
D(Delete)
- V(Visualized selection)
- GU(Change to uppercase)
- Gu(Small write)
(Chen Hao Note: Visual selection is a very interesting command. You can press v first and move the cursor to see the selected text. Then, you may d, y or uppercase)
0 ^
$
f
F
t
T
,
;
0→ To the line Header
^→ The first non-blank character to the line
$→ End of line
G _→ The last line is not the position of the blank character.
Fa→ To the next character with a, you can also use fs to the next character with s.
T,→ The first character before the comma. A comma can be another character.
3fa→ Search for the third a in the current row.
FAndT
→ Andf
Andt
Same, but in the opposite direction.
Dt"→ Delete all content until double quotation marks --"。
<Action> a <object>Or<action>i<object>
<Action> a <object>And<action>i<object>
D(Delete ),
y
(Copy ),
v
(You can select the mode as needed ).
- WOne word,
W
A word separated by spaces,s
One sentence,p
A paragraph. It can also be a special character:"、
'、
)、
}、
]。
(Map (+) ("foo ")). The cursor key is in the firsto
.
Vi"→ Select
foo
.
Va"→ Select"foo"
.
Vi)→ Select"foo"
.
Va)→ Select("foo")
.
V2i)→ Selectmap (+) ("foo")
V2a)→ Select(map (+) ("foo"))
0 <C-v> <C-d> I -- [ESC]
^→ To the line Header
- <C-v>→ Start block Operation
- <C-d>→ Move down (you can also use hjkl to move the cursor, use %, or something else)
- I -- [ESC]→ I is insert, insert"
--
", Press ESC to take effect for each row.
Instead<C-v>
,<C-v>
Is to copy the clipboard.
<C-n>And
<C-p>
<C-p> or <C-n> ......
QaOperation Sequenceq
,@a
,@@
QaRecord your operations in the register
a。
- @Macro that will replay the recording.
- @@Is a shortcut key used to replay the macro of the latest recording.
Example
QaYp <C-a> q→
QaStart recording
- YpCopy rows.
- <C-a>Add 1.
- QStop recording.
- @→ Write down 2 below 1
- @@→ Write 3 in front of 2
- 100 @@A new 100 row is created and the data is increased to 103.
,V
,<C-v>
<C-v>(In Windows, it should be <C-q>). We can usev
AndV
. Once selected, you can do the following:
J→ Connect all rows (into one row)
- <Or
>
→ Left and right indent
- =→ Auto indent (Chen Hao note: this function is quite powerful and I like it too much)
<C-v>
JOr<C-d>
Or/pattern
Or%
......)
$To the end of the line
A, Input string, pressESC。
Andvsplit
.
: Help split. You can refer to the previous article VIM split screen on this site.
: Split→ Create a split screen (
:vsplit
Create a Vertical Split screen)
<C-w> <dir>: Dir is the direction, which can behjkl
Or one of them, which is used to switch the split screen.
<C-w> _(Or<C-w>|
): Maximize the size (<C-w> | Vertical Split screen)
<C-w> +(Or<C-w>-
): Increase the size.
- : Help usr_02.txt.
- !,Directory, register, plug-in, and many other functions.