command to enter VI
VI FileName: Opens or creates a new document and places the cursor at the beginning of the first line
VI +n FileName: Opens the document and places the cursor at the beginning of nth
VI + FileName: Opens the document and places the cursor at the beginning of the last line
VI +/pattern FileName: Opens the document and places the cursor at the first and pattern matching string
Vi-r FileName: The last time you were editing with VI, a system crash occurred, restoring filename
VI filename....filename: Open multiple documents, edit them in turn
Move Cursor Class command
H: Move the cursor one character to the left
L: Move the cursor right one character
Space: Move the cursor right one character
Backspace: Cursor moves left one character
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 beginning of the word
B or B: The cursor moves left one word to the beginning of the word
E or E: Move the cursor right one word j to the end of the word
): Move the cursor to the end of the sentence
(: The cursor moves to the beginning of the sentence
}: Move the cursor to the beginning of the paragraph
{: Cursor moves to end of paragraph
NG: Cursor moves to the beginning of nth
n+: The cursor moves down n rows
N: Move the cursor up n rows
n$: Cursor moves to end of Nth line
H: Move the cursor to the top row of the screen
M: Move the cursor to the middle line of the screen
L: The cursor moves to the last line of the screen
0: (note is the number 0) cursor moves to the beginning of the current line
$: Cursor moves to the end of the current line
Screen Tumbling Class command
Ctrl+u: first half screen to document
Ctrl+d: Half-screen to document end
CTRL+F: Flip a screen to the end of a document
ctrl+b; Turn one screen to the top of the document
NZ: Rolls line N to the top of the screen and scrolls the current line to the top of the screen when n is not specified.
Insert Text Class command
I: Before the cursor
I: At the beginning of the current
A: After the cursor
A: At the end of the current line
O: A new line below the current line
O: New row above the current line
R: Replace the current character
R: Replaces the current character and its 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 input text
NCW or NCW: Modifies a specified number of words
NCC: Modifying a specified number of rows
Delete command
NDW or NDW: Delete the n-1 characters at the beginning and after the cursor
Do: Delete to the beginning of the line
d$: Delete to end of line
NDD: Deletes the current line and its subsequent n-1 rows
X or x: Deletes a character, x deletes the cursor, and x deletes the cursor before the
Ctrl+u: Delete text entered under input mode
Search and Replace commands:
/pattern: Searches for pattern at the end of the document from the beginning of the cursor
? pattern: Searches for pattern from the beginning of the cursor to the first document
N: Repeat the last search command in the same direction
N: Repeats the last search command in the opposite direction
: s/p1/p2/g: Replaces any P1 in the current row with P2
: n1,n2s/p1/p2/g: Replace any P1 in line N1 to N2 with P2
: g/p1/s//p2/g: Replace any p1 in the document with P2
Option configuration
All: List any configuration of options
Term: Configure terminal type
Ignorance: ignoring case in search
List: Display tab stops (CTRL+I) and end-of-line flags ($)
Number: Show line numbers
Report: Displays the number modified by the line-oriented command
Terse: Displays a short warning message
Warn: Displays no write message if the current document is not saved when you go to another document
Nomagic: Allows the use of special characters that are not preceded by "\" In search mode
Nowrapscan: Prohibit vi from reaching the end of the document and starting at the other end
MESG: Allow VI to display information that other users write to their terminal using write
Last line mode command
: N1,N2 CO N3: Copy the contents of the N1 line to the N2 row below the N3 line
: n1,n2 m N3: Move the contents of the N1 line to the N2 line below the N3 line
: n1,n2 d: Delete the contents of N1 rows to N2 rows
: w: Save current document
: E filename: Open document filename for editing
: x: Saves the current document and exits
: Q: Exit VI
: q!: Do not save the document and Exit VI
:!command: Execute shell command
: n1,n2 W!command: Enter the contents of the N1 line to the N2 line in the document as input to the command, and if you do not specify N1,N2, the input of the entire document content as the command
: R!command: Puts the command's output to the current line.
Linux VI command details and usage tips