Use of Linux -- vi, linuxvi
Record some instructions for using vi. The blue part is commonly used, and the used part is re-described. A few parts are not used, there are still some unused items that are not recorded and will be supplemented later:
References: http://cn.linux.vbird.org/linux_basic/0310vi_2.php
Vi has three modes: general mode, edit mode, and command column command mode. The functions are as follows: general mode:
Open a document in vi and directly enter the General mode, that is, the default mode. In this mode, you can use the [Up, down, left, right] button to move the cursor, you can use [delete character] or [Delete entire line] to process content, or use [copy and paste] to process file data.
Edit mode:
In the default mode, you can delete, copy, and paste the file, but you cannot edit the file content. You have to press [I, I, o, O, a, A, r, r] enters the editing mode only after any letter. In Linux, when you press these buttons, INSERT or REPLACE appears at the bottom left of the screen. To exit the editing mode and return to the default mode, press the [ESC] button.
Command column command mode:
In the default mode, enter 【:/?] You can move the cursor to the bottom line. In this mode, you can [search for materials], read, save disks, replace a large number of characters, exit vi, display row numbers, and so on.
Note: The general mode is that the default mode can be switched to the edit mode and command column command mode, but the edit mode and command column command mode cannot be switched to each other.
Button Description: general mode available button description, cursor movement, copy and paste, search replacement, etc.: move the cursor method:
H or move to the left arrow key: Move a character to the left, move multiple times, and add the number of times to move before [h or left arrow key], for example, 5 h, move 5 characters to the left.
J or downward arrow: move the cursor down a row, move multiple rows, [j or downward arrow] add the number of rows to move, for example, 10j, move 10 rows downward.
K or Up Arrow: move the cursor up a row, move multiple rows, [k or up arrow] add the number of rows to move, for example, 16 k, move up 16 rows.
L or right arrow: move the cursor one character to the right and move it multiple times. [l or right arrow] add the number of times to move before, for example, 10l, move 10 characters to the right.
CTRL + f: Move a Page Down, which is equivalent to Page Down.
CTRL + B: the screen moves one Page Up, which is equivalent to the Page Up button.
CTRL + d: Move the screen down for half a page.
CTRL + u: the screen is moved up half a page.
+: Move the cursor to the next column without space characters.
-: Move the cursor to the previous column without space characters.
N <space>: n indicates a number. Press the number and then press the Space key. The cursor moves to the right to the nth character in the line.
Note: The difference between n <space> and h and l in Centos6.8 is that the former: if the number of characters to be moved exceeds the number of characters to be moved from the other row, the latter will not.
0 or [HOME] key: number 0, move to the top character of this line.
$ Or [END] key: Move to the last character of this line.
H: move the cursor to the first character in the top line of the current screen.
M: move the cursor to the first character in the center of the current screen.
L: move the cursor to the first character in the bottom line of the current screen.
G: Move to the last line of the current document.
NG: n indicates the number, which is the nth row of the current document.
Gg: Move to the first line of the current document.
N <ENTER>: n is a number, and the cursor moves down n rows.
Search and replace:
/Word: search for a string named word under the cursor [Down. Locate the first occurrence of the word.
? Word: search for a string named word above the cursor [Up. Locate the first occurrence of the word.
N: n. Press the English button to repeat the previous search action. Continue the search.
N: N. Press the English button to repeat the previous search. Continue searching in reverse order.
: N1, n2s/world1/word2/g: n1 and n2 are numbers. Find the world1 string between n1 and n2 and replace it with word2.
: 1, $ s/world1/word2/g: searches for the string world1 from the first line to the last line, and replaces the string with word2. Global replacement.
: 1, $ s/world1/word2/gc: searches for the string world1 from the first line to the last line, replaces the string with word2, and prompts the user to confirm replacement before replacement. Global replacement, prompting whether to replace.
Delete, copy, and paste:
X, X: In a row of characters, x deletes one character backward, which is equivalent to the [DEL] key, X deletes one character forward, and is equivalent to the [BACKSPACE] key.
Nx: n is a number and n characters are deleted consecutively.
Dd: Delete the entire row where the cursor is located.
Ndd: n number. Delete n rows down the cursor. Includes the row where the cursor is located.
D1G: delete all data from the row where the cursor is located to the first row. Includes the row where the cursor is located.
DG: delete all data from the row where the cursor is located to the last row, including the row where the cursor is located.
D $: Delete the last character from the cursor to the row.
D0: 0 Number 0. Delete the cursor and the character at the beginning of the row.
Yy: copy the content of the row where the cursor is located
Nyy: n is a number. copy the data from the row where the cursor is located to the next n rows, including the row where the cursor is located.
Y1G: Copy all data from the row where the cursor is located to the first row.
YG: Copy all data from the row where the cursor is located to the last row.
Y0: Copy all data from the cursor to the beginning of the row.
Y $: Copy all the data from the cursor to the end of the row.
P: paste the copied data in the next row where the cursor is located.
P: paste the copied data on the row where the cursor is located.
U: restores the previous action.
[Ctrl] + r: redo the previous action.
.: Decimal point. Repeat the previous action.
Switch to edit mode in normal mode. Available buttons:
I, I: Enter the editing mode to insert, I insert at the cursor, I insert at the first non-space character in the row where the cursor is located.
A, A: Enter the editing mode for insertion. Insert starts at the next character where a cursor is located, and insert starts at the last character in the line where A cursor is located.
O, O: Enter the editing mode to Insert a new row, and Insert a new row in front of the row where the current cursor is located.
R, R: Enter the edit mode to replace the cursor. r replaces the character of the cursor once, and R replaces the character of the cursor until [ESC.
Note: In the editing mode, the words "-- INSERT --" or "-- REPLACE --" appear in the lower left corner of the vi image.
[ESC]: exit the editing mode and enter normal mode.
Switch the normal mode to the command column mode. Available buttons: Command column storage, exit, and other commands:
: W: Write the edited data to the hard disk document.
: Wq: store and leave. : Wq! Forcibly store and exit
: Q: Leave vi
: Q! : Force exit without storing the modified content of the document.
ZZ: if the document has been changed, it is stored and left. If it has not been changed, it is not stored and left.
: W [filename]: stores the edited data as another document.
Vim environment change:
: Set nu: displays the row number.
: Set nonu: cancel the row number.