Create File "VI"
First, the order to enter VI
VI FileName: Open or create a new file and place the cursor at the beginning of the first line
VI +n FileName: Open the file and place the cursor at the beginning of nth
VI + FileName: Open the file and place the cursor at the end of the line
VI +/pattern FileName: Open the file and place the cursor in the first matching string
Vi-r filename: A system crash occurred during the last edit with VI, filename restored
VI filename....filename: Open multiple files, edit in sequence
Second, Move cursor class command
H: Move the cursor one character to the left
L: The cursor moves one character to the right
Space: The cursor moves one character to the right
Backspace: Move the cursor one character to the left
K or ctrl+p: Move the cursor up one line
J or CTRL + N: Move the cursor down one line
Enter: Move the cursor down one line
W or W: Move the cursor right one word to the top of the word
B or B: Move the cursor left one word to the top of the word
E or E: Move the cursor right one word to the end of the word
): The cursor moves to the end of the sentence
(: The cursor moves to the beginning of the sentence
}: The cursor moves to the beginning of the paragraph
{: The cursor moves to the end of the paragraph
NG: The cursor moves to the beginning of nth
n+: Move the cursor down n line
N: Move n line up on cursor
n$: The cursor moves to the end of the nth line
H: The cursor moves to the top line of the screen
M: The cursor moves to the middle line of the screen
L: The cursor moves to the last line of the screen
0: (note is the number 0) the cursor moves to the current beginning
$: The cursor moves to the end of the current line
Third, screen rolling class command
Ctrl+u: Turn to file first half screen
Ctrl+d: Turn to file tail half screen
CTRL+F: Flip a screen to the end of the file
Ctrl+b to the first screen of a file
NZ: Rolls the nth row to the top of the screen and rolls the current row to the top of the screen without specifying N.
Iv. inserting text class commands
I: Before the cursor
I: At the beginning of the current
A: After the cursor
A: At the end of the current line
O: Open a new row below the current line
O: Open a new line above the current line
R: Replace the current character
R: Replaces the current character and its subsequent characters until the ESC key is pressed
S: replaces the specified number of characters with the input text, starting at the current cursor position
S: Deletes the specified number of rows and replaces them with the text entered
NCW or NCW: Modifying a specified number of words
NCC: Modify specified number of rows
V. Delete command
NDW or NDW: Deletes the beginning of the cursor and the n-1 word after it
Do: Delete to the beginning of the line
d$: Delete to end of line
NDD: Deletes the current row and its n-1 line
X or x: Deletes a character, x deletes the cursor, and x deletes the cursor before the
Ctrl+u: Deletes the text entered in the input mode
Vi. Search and Replace commands
/pattern: Searches the end of the file for pattern at the beginning of the cursor
Pattern: Search for pattern from the beginning of the cursor to the first file
N: Repeat the last search command in the same direction
N: Repeat the last search command in the opposite direction
: s/p1/p2/g: Replaces all P1 in the current row with P2
: n1,n2s/p1/p2/g: All P1 in the N1 to N2 line are replaced with P2
: g/p1/s//p2/g: Replace all P1 in the file with P2
Seven, vi command use examples
Exit VI
In instruction mode type: Q,:Q!,:WQ or: X (note: number), will exit VI. Where: Wq and: X is to save the exit, and: Q is to exit directly if the file has a new change, vi will prompt you to save the file and: Q command will also fail, at this time you can use: w command to save the file and then use: Q Exit, or with: Wq or: X command exit, if you do not want to save the changes after the file, you need to use: Q ! command, this command will not save the file and Exit VI directly.
Exit after save, add exclamation point is mandatory: wq! (also can modify read-only file)