Part 1: Description of buttons available in general mode, move the cursor, copy and paste, and replace search
How to move the cursor
H. move the cursor to the left arrow for one character.
J. Or a down arrow. The cursor is a character that moves downward.
K or move the cursor up to a character
L or move one character to the right from the arrow (→)
If you put your right hand on the keyboard, you will find that hjkl is arranged together, so you can use these four buttons to move
Cursor. If you want to move multiple times, for example, move 30 rows down, you can use the combination of "30j" or "30 rows"
Key, that is, add the number of times (number) You want to perform, press the action!
[CTRL] + [f] the screen moves one page down, which is equivalent to a few [Page Down] buttons (commonly used)
[CTRL] + [B] Move one page up on the screen, which is equivalent to a few [page up] buttons (commonly used)
[CTRL] + [d] Move the screen down half page
[CTRL] + [u] screen "up" move half page
+ Move the cursor to the next column with a non-space character
-Move the cursor to the previous column of a non-space character.
N <space> that N represents a number, for example, 20. Press the number and then press the Space key. The cursor shifts the n characters of the line to the right. For example, 20 <space> will move the cursor to the back
Distance of 20 characters.
0 or function key [home] This is a number "0": Move to the top character of this line (commonly used)
$ Or the function key [end] Moves the cursor to the last character of the cursor line (commonly used)
H move the cursor to the first character in the line at the top of the screen
M cursor moves to the first character of the line in the center of the screen
L move the cursor to the first character in the line at the bottom of the screen cursor
G moves to the last line of the file (frequently used)
Ng n is a number. The Nth row of the file. For example, 20 GB will be moved to this file.
The first line of the case (can be used with: Set Nu)
Gg moves to the first line of this file, which is equivalent to 1 GB! (Common)
N <enter> N is a number. Move the cursor down n rows (commonly used)
/Word searches for a string named word under the cursor. For example
Enter the vbird string! (Common)
? Word searches for a string named word on top of the cursor.
N is an English button. Indicates "repeat the previous search action 』. For example
If we execute/vbird to search for the vbird string, press n to continue searching for the next string named vbird. If it is execution? Press n to search for a string named vbird!
N is an English button. Opposite to N, perform the previous seek action for "reverse. For example, after/vbird, press n to search for vbird "up.
It is very helpful to use/word with N and n! You can repeat to find some keywords you are searching!
: N1, N2s/word1/word2/g N1 and N2 digits. Search for the word1 string between line N1 and line N2 and replace it with word2! For example, search for vbird between 100 and 200 and replace it with vbird ": 100,200 S/vbird/g 』. (Common)
: 1, $ S/word1/word2/g search for the word1 string from the first line to the last line, and replace this character as a string with word2! (Common)
: 1, $ S/word1/word2/GC word2! Search 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 confirm (confirm) whether to replace! (Common)
Delete, copy, and attach
X, X
In a row, X deletes a character (equivalent to a [del] Key) backward, and X deletes a character (equivalent to a blank [backspace] or a return key)
Nx n is a number and n characters are deleted consecutively. For example, I want to delete 10 characters in a row, "10x 』.
Dd deletes the entire column of the cursor (commonly used)
Ndd n is a number. Delete the n-down column where the cursor is located. For example, if 20dd is used, 20 columns are deleted (usually used)
D1g delete all data from the cursor to the first row
DG deletes all data from the cursor to the last row
D $ Delete the last character of the cursor
D0 is the number 0, where the cursor is deleted, to the beginning of the row.
YY copy the row of the cursor (commonly used)
Nyy N is a number. Copy the n-down column where the cursor is located. For example, if 20yy is used, 20 columns are copied (usually used)
Y1g copy all data from the cursor column to the first column
YG copies all data from the cursor column to the last column
Y0 copies the character of the cursor to all data at the beginning of the row.
Y $ copy all data from the character with the cursor to the end of the row
P and P are used to paste the copied data on the next row of the cursor, and P is used to paste the previous row on the cursor! For example, I have already copied 10 rows of data with the cursor in 20th rows. After you press P, the 10 rows of data will be pasted after the original 20 rows, that is, from 21 rows.
But what if I press P? Then the original 20th rows will be pushed to 30 rows. (Commonly used)
J. Combine the data in the column where the cursor is located with the data in the next column into the same column
C. Delete multiple data records repeatedly. For example, delete 10 rows down and [10cj]
U restores the previous action. (Common)
[CTRL] + R redo the previous action. (Common)
This U does not [CTRL] + R is a very common command! One is restoration, the other is redo once ~ Use these two functions
Key, your edits, hey! Happy!
Don't doubt! This is the decimal point! It means to repeat the previous action. If you want
You just need to delete and repeat the action, and press the decimal point! (Common)
Part 2: Description of available buttons for switching from normal mode to edit mode
Enter the insert or replace edit mode
I, I enter the insert mode: I is "insert from the current cursor", I is "the first non-empty in the current row"
Start to insert at the grid 』. (Common)
Insert mode ):
A,
A is "insert from the next character of the current cursor", and a is "insert from the last character of the row where the cursor is located 』. (Common)
Insert mode ):
This is the case of the English letter O. O is "Insert at the next line where the current cursor is located"
A new row "; O inserts a new row into the previous row where the current cursor is located! (Commonly used)
R and R enter replace mode: R will replace the character where the cursor is located only once, and R will replace the text where the cursor is located all the time,
Until ESC is pressed; (commonly used)
In the buttons above, the words "-- insert --" or "-- replace --" will appear in the lower left corner of the VI image. By
The name will show the action !! Note that we mentioned above that when you want to input characters in the file,
You must see insert or replace in the lower-left corner to enter it!
[ESC] exit the editing mode and return to normal mode (commonly used)
Part 3: Description of the buttons available for switching from general mode to command column Mode
Command columns, such as marker for storing and removing commands
: W writes the edited data to the hard disk file (commonly used)
: W! If the file attribute is "read-only", the file is forcibly written. However, whether the file can be written is related to the permission on the file!
: Q leaves 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.
Note that the exclamation point (!) In VI, it often means "forced ~
: WQ is stored and left. If it is: WQ! It is forced to save and leave (commonly used)
ZZ is an uppercase Z! 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] stores the edited data into another file (similar to storing a new file)
R: [filename] reads data from another file in the edited data. Add the file "FILENAME" to the end of the row where the cursor is located.
: N1, N2 W [filename] store the content from N1 to N2 into the filename file.
:! Command temporarily leaves VI to display the result of Executing command in command column mode! For example
『:! Ls/Home> to view the LS output file information under/home in Vi!
Vim Environment Change
: Set nu displays the row number. After the row is set, the row number is displayed in the prefix of each row.
: Opposite to set Nu, set Nonu is the canceled row number!
This article from the "no trace of Sorrow" blog, please be sure to keep this source http://2845621599.blog.51cto.com/8221220/1549892
Summary of VIM use methods taken from laruence's private dish