Summary of Vim quick operations in Linux and vim quick operations
How to move the cursor
H. move the cursor to the left by using the left arrow key.
J or the down arrow (←) move the cursor down a character
K or the up arrow (←) move the cursor up a character
L or right arrow (→) move the cursor one character to the right
[Ctrl] + [f] the screen moves one Page Down, which is equivalent to a [Page Down] button (commonly used)
[Ctrl] + [B] The screen moves one Page Up, which is equivalent to a [Page Up] button (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 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.
0 or function key [Home] This is a number "0": Move to the top character of this line (commonly used)
$ Or move the function key [End] to the End of the 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 screen
L move the cursor to the first character in the row at the bottom of the screen
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 the 20th rows of this file (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)
Search and replace
/Word searches for a string named word under the cursor. For example, to search for the vbird string in the file, enter/vbird! (Common)
? Word searches for a string named word on top of the cursor.
N is an English button. Indicates "repeat the previous search 』. For example, if we just run/vbird to search down the vbird string,
After you press n, the system continues 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. In contrast to n, the previous search for reverse is performed. For example, after/vbird, press N to search for vbird "up.
: N1, n2s/word1/word2/g n1 and n2 are numbers. Search for the word1 string between line n1 and line n2 and replace it with word2!
For example, if you search for vbird between 100 and 200 and replace it with VBIRD: ": 100,200 s/vbird/VBIRD/g 』. (Common)
: 1, $ s/word1/word2/g searches for the word1 string from the first row to the last row, and replaces this string with word2! (Common)
: 1, $ s/word1/word2/gc searches for the word1 string from the first row to the last row, and replaces the string with word2! The prompt characters are displayed before replacement to confirm (confirm) whether to replace! (Common)
Delete, copy, and paste
X, X in a row, x is to delete a character backward (equivalent to a pair of [del] keys), X is to delete a character forward (equivalent to a pair of [backspace], that is, the Return key) (common)
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, 20 dd deletes 20 columns (commonly used)
D1G delete all data from the cursor to the first row
DG delete all data from cursor to last row
D $ Delete the cursor to the last character of the row
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 (commonly 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, P p: paste the copied data to the next row of the cursor, and P to the last row of the cursor!
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)
. Do not doubt! This is the decimal point! It means to repeat the previous action. If you want to repeat deletion, repeat, and so on, just press the decimal point! (Common)
Enter the insert or replace edit mode
I, I is "insert from the current cursor", I is "insert from the first non-space character in the current row 』. (Common)
A, 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)
O, O is the case of the English letter "o. O is to insert a new row in the next row where the current cursor is located. O is to insert a new row in the previous row where the current cursor is located! (Common)
R, R r will only represent the character of the cursor once; R will always represent the text of the cursor until ESC is pressed; (commonly used)
Commands for storing and removing command Columns
: 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.
: 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 as filename.
:! 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!
Significance of the button selected by the block
If you select the v character, the cursor is reversed!
If you select row V, the rows with the cursor passed are reversed!
[Ctrl] + v block selection, you can use a rectangle to select materials
Y copies the anti-whitelist.
D. Delete the anti-whitelist.
Buttons for editing multiple files
Vim/host1.conf/host2.conf edit multiple files
: N: edit the next file
: N: edit the previous file
: Files: Lists All files enabled by vim.
Button Function in Multi-Window Mode
: Sp [filename] opens a new window. If filename is added, a new file is opened in the new window. Otherwise, the two windows are the same file content (synchronously displayed ).
[Ctrl] + w + j: Press [ctrl] first, and then press w to open all the buttons, then press j (or the down arrow) to move the cursor to the lower window.
[Ctrl] + w + ←
[Ctrl] + w + k is the same as above, but the cursor moves to the above window.
[Ctrl] + w + ←
[Ctrl] + w + q is actually: q is over! For example, if I want to end the window below, use [ctrl] + w + ← to move to the window below and press: q to exit, you can also press [ctrl] + w + q!
Vim environment setting parameters
: 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 nonu, It is the cancel row number!
: Set hlsearch is high light search ). This is to set whether to reverse the white value of the searched string. The default value is hlsearch.
: Set nohlsearch
: Is set autoindent automatically scaled down? Autoindent means automatic contraction.
: Set noautoindent
: Does set backup automatically store backup files? Generally, it is nobackup. If backup is set, when you change any file, the source file will be saved as another file named filename ~ .
: Set r do you still remember some descriptions of the status bar in the lower right corner? This ruler is displaying or not displaying the set value!
: Set showmode: whether to display the status bar in the lower left corner of the -- INSERT -- or other words.
: Set backspace = (012) in general, if we press I to enter the edit mode, we can use the backspace key to delete any character.
However, this is not allowed for some distribution. In this case, we can set it through backspace ~ When backspace is 2
You can delete any value. When the value is 0 or 1, you can only delete the character you just entered, but cannot Delete the existing text!
: Set all displays all the currently set environment parameters.
: Set displays the set parameters that are different from the default values of the system. Generally, you have set parameters that you have changed on your own!
: Does syntax on display different colors based on program-related syntaxes? For example, when editing a plain text file, if it starts with #, the line turns blue. If you know how to write
: Syntax off, so this: syntax on will take the initiative to help you correct it! However, if you only write plain text files and want to avoid the interference of color on your screen, you can cancel this setting.
: Set bg = dark can be used to display different color tones. The default value is "light 』.
: Set bg = light