Record some of the use of VI instructions, the blue part is more commonly used, wherein the use of the re-described, very few are unused, and some are not used or recorded in, follow-up to supplement the amendment:
Reference: http://cn.linux.vbird.org/linux_basic/0310vi_2.php
VI Three modes: General mode, edit mode, command-line commands mode, the role of the following:General mode:
Open a document with VI directly into the general mode is the default mode, in this mode, you can use the "up, down, left, right" keys to move the cursor, you can use "delete character" or "Delete whole line" to work with the content, you can also use "copy, paste" to work with file data.
edit mode:
In the default mode, you can delete, copy, paste, and so on, but cannot edit the contents of the file, you have to press "I,i,o,o,a,a,r,r" and so on any one letter before entering the editing mode. Usually in Linux, when you press these keys, the words "INSERT or REPLACE" appear at the bottom left of the screen, so you can edit them. If you want to exit edit mode and return to the default mode, press the [ESC] button.
Instruction-column command mode:
In the default mode, enter any of the three ":/?" to move the cursor to the bottom row. In this mode, you can provide your "search data" action, read, save, a large number of substitution characters, leave VI, display line number and so on is achieved in this mode.
Note: The normal mode is the default mode to switch between edit mode and instruction column command mode, but the edit mode and Instruction column command mode cannot be toggled with each other.
Key Instructions :General ModeAvailable button descriptions, cursor movement, copy and paste, search substitution, etc.:How to move the cursor:
h or LEFT ARROW key: The cursor moves one character to the left, moves multiple times, "H or left arrow key" before adding the number of times to move, for example, 5h, move 5 characters to the left.
J or DOWN ARROW key: Move the cursor down one line, multi-line move, "J or DOWN ARROW key" before adding the number of rows to be moved, for example, 10J, Move down 10 rows.
K or UP ARROW key: Move the cursor up one line, multi-line move, "K or Up ARROW key" before adding the number of lines to move, for example, 16k, move up 16 rows.
L or RIGHT ARROW key: The cursor moves to the right one character, moves multiple times, "L or right ARROW key" before adding the number of times to move, for example, 10l, move 10 characters to the right.
"CTRL" + "F": the screen moves down one page, equivalent to the "Page Down" button.
"CTRL" + "B": the screen moves up one page, equivalent to the "Page Up" button.
"CTRL" + "D": the screen moves down half a page.
"CTRL" + "U": the screen moves up half a page.
+: The cursor moves to the next column of non-whitespace.
-: The cursor moves to the previous column of non-whitespace.
N<space>: N represents a number. When you press the number and then press the SPACEBAR, the cursor moves to the nth character of the line to the right.
Note the difference between:n<space> and H and L in Centos6.8 is that the former: if the moved character exceeds the line, the remaining characters continue to move, and the latter does not.
0 or "HOME" key: number 0, move to the front character of this line.
$ or "End" key: Moves to the last face character of this line.
H: The cursor moves to the first character of the line at the top of the current screen.
M: The cursor moves to the first character of the center line of the current screen.
L: The cursor moves to the first character at the bottom line of the current screen.
G: Moves to the last line of the current document.
Ng:n is a number that moves to the nth row of the current document.
GG: Moves 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: "Down" under the cursor to find a string named word. Navigate to the first place where the word appears.
Word: "Up" above the cursor looks for a string named word. Navigate to the first place where the word appears.
"N", the English key, repeats the previous search action. Continue with the search.
N: =, English keys, reverse the previous search action. Reverse continues the search.
: n1,n2s/world1/word2/g: N1 and N2 are numbers, look for N2 strings between N1 to World1, and replace the string with Word2.
: 1, $s/world1/word2/g: look for the string world1 from the first line to the last line, and replace the string with Word2. Global substitution.
: 1, $s/world1/word2/gc: look for the string world1 from the first line to the last line, and replace the string with Word2, which prompts the user to confirm the substitution. Global substitution, indicating whether to replace.
Delete, copy, paste:
X,x: In one line of words, X deletes a character backwards, equivalent to the "DEL" key, and X deletes a character, which is equivalent to the "BACKSPACE" key.
Nx:n is a number that continuously deletes n characters backwards.
DD: Deletes the entire row of the line where the cursor is located.
Ndd:n the number, delete the row that contains the cursor down n rows. Include the line where the cursor is located.
D1G: Deletes all data from the row to the first row of the cursor. Include the line where the cursor is located.
DG: Removes all data from the row to the last row of the cursor. Includes the line where the cursor is located.
d$: Deletes the last character of the line to which the cursor is located.
d0:0 the number 0, delete the cursor at the top of the line, to the front of the character.
YY: Copy the contents of the line where the cursor is located
Nyy:n is a number that duplicates the row of rows down n rows of data, including the row where the cursor is located.
Y1G: Copies all data from the row to the first row of the cursor.
YG: Copies all the data from the row to the last row of the cursor.
Y0: Copies all data at the beginning of the line at the cursor location.
y$: Copies all data at the end of the line at the cursor location.
P: Pastes the copied data on the next line where the cursor is located.
P: Pastes the copied data on the same line as the cursor.
U: Restores the previous action.
[Ctrl]+r: Redo the previous action.
. : A decimal point, repeating the previous action.
General mode switch to edit mode available button:
I,i: Enter edit mode to insert, I insert at the cursor, I cursor in the row of the first non-whitespace space to start inserting.
A,a: Enter edit mode for insert operation, a cursor at the next character at the beginning of the insertion, a cursor at the end of the line at the beginning of the insertion.
O,o: Insert in edit mode, lowercase English letter o insert a new line after the current cursor row, capital letter o The current cursor is inserted into a new line before the row.
R,r: Enter edit mode to replace the action, R replaces the character of the cursor one time, R replaces the character of the cursor until "ESC".
Note: Enter the editing mode, the bottom left corner of the VI screen will appear "--insert--" or "--replace--" words.
[ESC]: Exit edit mode and enter normal mode.
General mode switch to instruction column mode available buttons:Instructions for storing and leaving instruction columns:
: W: Writes the edited data to the hard disk document.
: Wq: Left after storage. : wq! forced to leave after storage
: Q: Leave VI
: q! : Forcibly leaves and does not store content that has been modified by the document.
ZZ: If the document is changed, it is stored and left, and if it is not changed, it is not stored.
: W[filename]: Storing edited data as another document
changes to the VIM environment:
: Set Nu: Displays line numbers.
: Set Nonu: Cancels the line number.
Use of Linux--vi