1. About exit
: WQ! ---- Force save and exit
: WQ ---- save and quit
: X ----- works the same as: WQ
ZZ ---- has the same role as: WQ (note that Z is capitalized and not in command mode)
: Q ---- exit
: Q! --- Force exit
========================================================== ======
2. About mobile
H: Move a character from the current row to the left.
J: Move to the next row
K: Move to the previous row.
L: move one character to the right of the current row
CTRL + F: Scroll one page forward
CTRL + B: Scroll back one page
: N: move the cursor to line N.
: $ Move the cursor to the last line
0. move the cursor to the beginning of the row.
$ Position the cursor at the end of the row
G. Position the cursor to the base.ArticleThe last line.
H. move the cursor to the top of the screen.
M positions the cursor in the middle of the screen
L move the cursor to the bottom of the screen
========================================================== ====
3. Search
/: The things to be searched inFileForward search
? : Search for the things to be searched in the file.
N: Repeated search forward
N: Repeated search
========================================================== =====
4. About Replication
YY: copy the current row of the cursor
Nyy: copy the n-1 line from the current row to the current row.
: 1,100 Co 200 will 1 ~ 100 of the content is copied to 200th rows.
: 100,102 Co $ change 100 ~ Copy the contents of the first row to the last row.
========================================================== ======
5. About pasting
P: paste it to the next row of the current row.
P (large): paste it to the previous row of the current row
========================================================== ======
6. About Delete. Cut
Dd deletes the current row
NDD is similar to nyy
DW deletes a word
Similar to NDD, ndw
X delete a character
NX Delete n characters
DG deletes all content from the current cursor to the end of the file.
D0 deletes all content from the current cursor to the beginning of the line
D $ delete all content from the current cursor to the end of the row
: 1, 100d delete 1 ~ 100
: 100d Delete 100th rows
: 1,100 Mo $ Change 1 ~ Move the content of Row 3 to the last row.
========================================================== =====
7. insert
I: Enter the insert mode before the characters in the current position
I: insert at the beginning of the current row
A: Enter the insert mode after the characters at the current position
A: insert at the end of the current row.
O: Insert a new row under the current row.
O: Insert a new row on the current row.
========================================================== =====
8. About Revocation
U: undo the last change
========================================================== =====
9. About replacement
Regexp: The pattern to be matched.
Replacement: string to be replaced
: S/Regexp/replacement ------------------------- Replace the first style of the current row
: S/Regexp/replacement/g ------------------------- replace all the matches in the current row
: % S/Regexp/replacement/g ----------------------- replace all matching styles in the file
========================================================== =====
PS: Another important command is the "." command, which is used to repeat the previous command.
In VI, how does one: undo the last operation ?, Repeat a group of Edit operations multiple times ?.......
A) undo the previous edit operation. ====> U
B) Repeat the previous edit operation. ====>.
C) restore the unedited operation. ======> Ctrl + R
D) repeat a group of edits multiple times. ====> "." Command can repeat the last edit action.
Handout VI of laruence's Linux private house dish