Use Linux_08_vi from scratch
Thank you for your reference. If you have any errors or questions, please leave a message to correct them. Thank you.
1. What is vi1 and vi: vi is the most common text editor under Linux/Unix.
2. vim: vim is an upgraded version of vi. It is not only compatible with all vi commands, but also has some new features.
Ii. Three working modes of vi
3. edit mode 1. Position the cursor. 2. Search for a string (:., $ s? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> counter + sg1 + counter/Counter + 7SuyKG0 + counter/6us3w2li0pgjypkg6s + 4 yOfPwrHty/Counter =" 1 "cellpadding =" 2 "cellspacing =" 0 "width =" 90% ">General mode:Move cursorH or the left arrowMove a character to the leftJ or down arrowMove the cursor down a characterK or up arrowMove the cursor one character upL or right arrowMove the cursor one character to the right[Ctrl] + [f]Move one page forward on the screen (frequently used)[Ctrl] + [B]Move one page backward (commonly used)[Ctrl] + [d]Move half of the screen "Forward"[Ctrl] + [u]Move half of the screen backward+Move the cursor to the next column with a non-space character-Move the cursor to the previous column of a non-space characterN <space>Press the number and then press the Space key. The cursor will move the n characters in the line to the right. For example, if the value is 20 <space>, the cursor moves the distance of 20 characters to the backend.0This is the number "0": Move to the top character of this line (commonly used)$Move to the last character of this line (commonly used)HMove the cursor to the top line of the screenMMove the cursor to the center of the screenLMove the cursor to the bottom line of the screenGMove to the last line of the file (frequently used)NGThe Nth row of the file. For example, 20 GB will be moved to 20 rows of this file (can be used with: set nu)N <Enter>Move the cursor down n rows (commonly used)General mode:Search and replace/WordSearch for a string named word after the cursor. (Common)? WordSearch for a string named word before the cursor.: N1, n2s/word1/word2/gSearch for the word1 string between line n1 and line n2 and replace it with word2! (Common): 1, $ s/word1/word2/gSearch for the word1 string from the first row to the last row and replace it with word2! (Common): 1, $ s/word1/word2/gcSearch for the word1 string from the first row to the last row and replace it with word2! The prompt characters are displayed before replacement to check whether the conform must be replaced! (Common)General mode:Delete, copy, and attachX, XX is to delete one character backward, and X is to delete one character forward (commonly used)NxDelete n characters from the backendDdDelete the entire column of the cursor (commonly used)NddDelete the n-down column where the cursor is located. For example, 20 dd deletes 20 columns (commonly used)D1GDelete all data from the cursor to the first rowDGDelete all data from the cursor to the last rowYyCopy the row of the cursor (commonly used)NyyCopy the n-down column where the cursor is located. For example, if 20yy is used, 20 columns are copied (commonly used)Y1GCopy all data from the cursor column to the first columnYGCopy all data from the column where the cursor is located to the last columnP, PP: the copied data is pasted on the next row of the cursor, and P is pasted on the previous row of the cursor! (Common)JCombine the cursor column with the data in the next column into the same columnCMultiple data records are deleted repeatedly, for example, 10 rows are deleted down and [10cj]URestore the previous action. (Common)
Iv. insert mode (edit mode)
Enter edit mode |
|
I, I |
Insert: insert the input text at the position of the current cursor. The existing text will be backward. (commonly used) |
A, |
Add: Input starts from the next word where the current cursor is located. The existing text will be backward: (commonly used) |
O, O |
Insert a new row: Enter text from the beginning of the next row where the cursor is located) |
R, R |
Replace: r will replace the character where the cursor is located; R will replace the text where the cursor is located until ESC is pressed; (commonly used) |
Esc |
Exit edit mode and return to normal mode (commonly used) |
V. Command mode (last line mode)
Command column command mode |
|
: W |
Write edited data to Hard Disk Files (frequently used) |
: W! |
If the file attribute is "read-only", the file is forcibly written to the file. |
: Q |
Exit vi (commonly used) |
: Q! |
If you have modified an archive and do not want to store it, use it! To force exit without storing files. |
: Wq |
Save and exit. If it is: wq! It is forced to save and leave (commonly used) |
: E! |
Restore the file to the original state! |
ZZ |
If the file is not changed, it will not be stored and left. If the file has been changed, it will be stored and left! |
: W [filename] |
Save edited data to another file (similar to storing new files) |
: R [filename] |
Read the data of another archive in the edited data. Add the file "filename" to the end of the row where the cursor is located. |
: Set nu |
Displays the row number. After the row is set, the row number is displayed in the prefix of each row. |
: Set nonu |
Opposite to set nu, the row number is canceled! |
N1, n2 w [filename] |
Store content from n1 to n2 as filename. |
:! Command |
The result of Executing command in command column mode is displayed when vi is temporarily removed! For example [:! Ls/home] |
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.