Kaiwii summarized my own experience in using vi or vim: First, move the cursor up and down: of course, use the arrow keys on the keyboard. (ps: What r, it is a pain to use vi. why should we remember so many commands ?) Simply remember one. press the "I" key to modify it. if you want to delete a character, use the backspace key to create a new one.
Kaiwii summarizes my experience in using vi or vim:
First,
Move the cursor up, down, and left: use the arrow keys on the keyboard.
Modify: (ps: What r and so on are all nonsense. using vi is inherently painful. what should we remember to do with so many commands ?)
Simply remember one. press the "I" key to enter the modification. if you want to delete the character, use the return key. if you want to create a new line, press enter. if you want to enter the character, enter Luo directly. To exit the modification, press "ESC ".
Save: Press ": w"
Exit and do not save: ": q !"
Save and exit: ": q"
Everything is so simple ......
By Kaiwii
Of course, if you are a complicated person, you can refer to the following article by a brother:
----------------- Happy demarcation line ()---------------------------------------------
Leaving the Window interface is indeed a very painful thing for a person who uses Microsoft's operating system from small to large. Fortunately, I have been playing DOS for two years, don't know anything like a fly without a head. But I have never seen the [root @ localhost] # input method ~ Dizzy ~
I had to face the scalp. Should I use Shell as the most important part to learn Linux? Where does the first step start? I still want to learn how to compile things! Most of the environments and settings should be done through the command line. Many configuration files also need to be opened and compiled in text mode (Windows understanding ......), So I decided to fix vi first!
What is vi? It is actually a linux text compiler. in any version of linux, there is a vi text compiler, which is a standard compiler based on UNIX kernel systems and is known as powerful, no less than any latest text compiler. However, there is no mouse or Window interface. let's start learning commands from scratch ~
The first step is to enter vi. enter vi at the [root @ localhost] # prompt <文件名> You can automatically edit the file or open a new file. In command mode, enter: q,: q! ,: Wq or: x, you can exit vi! I tried it and it was quite easy to use. After counting the save and release commands of vi, we made a table as follows:
: W: save the current file
: E filename: open the file filename and edit it.
: X: save the current file and exit.
: Q: Exit vi.
: Q! : Do not save the file and exit vi
Next is the vi operation mode ~ Vi has two operation modes: command mode and input mode. Good understanding ~ In command mode, the input character is actually considered by the system to be the input of some corresponding commands, but not the corresponding character. In the input mode, the content of the document is actually compiled. Of course, if you want to switch from the command mode to the input mode, you only need to type the corresponding command. when you switch from the input mode to the command mode, you need to press a few more ESC commands. when you hear the prompt, it is the command mode ~
The following command table is used to import the command mode to the input mode:
Add a: enter a character from the bottom of all current cursor positions
A: input from the end of the current cursor row
Insert I: insert a new character from the left of the current cursor position. the content after the cursor moves backward with the new character
I: insert characters starting from the first non-blank character in the row where the cursor is currently located
Start New Line o: add a new line under the row where the cursor is currently located, and move the cursor to the beginning of the next line
O: add a line above the row where the cursor is located and input the mode.
It seems quite troublesome, but it seems like getting used to it slowly ~ Now, let's go to bed ...... Catch a cold is not all good yet ~
Finally, let's look at the summary table of the vi command for future query ~
Access the vi command
Vi filename: open or create a 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 line n
Vi + filename: open the file and place the cursor at the beginning of the last line
Vi +/pattern filename: open the file and place the cursor at the first string matching pattern
Vi-r filename: a system crash occurred when vi was being edited last time, restoring filename
Vi filename ...... Filename: open multiple files and edit them in sequence.
Move cursor command
H: Move the cursor one character to the left
L: Move the cursor one character to the right
Space: Move the cursor one character to the right
Backspace: Move the cursor one character to the left
K or Ctrl + p: Move the cursor up a row
J or Ctrl + n: Move the cursor down a row
Enter: move the cursor down a row
W or W: move one word to the beginning of the word to the right of the cursor.
B or B: move one word left to the beginning of the word
E or E: move one word to the end of the word to the right of the cursor.
): Move the cursor to the end of the sentence.
(: Move the cursor to the beginning of the sentence.
}: Move the cursor to the beginning of the paragraph
{: Move the cursor to the end of the paragraph
NG: Move the cursor to the beginning of line n
N +: Move the cursor down n rows
N-: Move n rows above the cursor
N $: Move the cursor to the end of line n
H: Move the cursor to the top line of the screen
M: Move the cursor to the middle line of the screen
L: Move the cursor to the last line of the screen
0: Move the cursor to the beginning of the current row
$: Move the cursor to the end of the current row
Screen tumble command
Ctrl + u: half screen at the beginning of the file
Ctrl + d: Flip the half screen to the end of the file
Ctrl + f: flip the screen to the end of the file
Ctrl + B: flip the screen to the beginning of the file
Nz: Rolls row n to the top of the screen. if n is not specified, the current row is rolled to the top of the screen.
Insert text commands
I: before the cursor
I: At the beginning of the current row
A: After the cursor
A: At the end of the current row
O: open a new row under the current row
O: open a new row above the current row.
R: replace the current character
R: replace the current and subsequent characters until you press ESC.
S: starting from the current cursor position, replace the specified number of characters with the input text
S: Delete a specified number of rows and replace them with the input text
Ncw or nCW: modify a specified number of characters
NCC: modifies a specified number of rows.
Delete Command
Ndw or ndW: n-1 characters starting at and following the cursor
Do: delete to the beginning of a row
D $: delete to the end of the row
Ndd: delete the current row and the next n-1 row
X or X: Delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.
Ctrl + u: delete text entered in input mode
Search and replace commands
/Pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Search for pattern from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.
: S/p1/p2/g: Replace all p1 in the current row with p2.
: N1, n2s/p1/p2/g: Replace all p1 from line n1 to line n2 with p2.
: G/p1/s // p2/g: Replace all p1 files with p2.
Option settings
All: lists all options.
Term: Set the terminal type
Ignorance: case insensitive in search
List: displays the stop table (Ctrl + I) and end mark ($)
Number: displays the row number.
Report: displays the number of changes made by line-oriented commands.
Terse: displays brief warning information
Warn: NO write information is displayed if the current file is not saved when it is transferred to another file.
Nomagic: Allows you to use special characters without "\" in search mode.
Nowrapscan: prohibit vi from searching at both ends of the file and starting from the other end.
Mesg: allows vi to display the information that other users write to their terminal using write.
Last-line command
: N1, n2 co n3: copy the content from line n1 to line n2 to line n3.
: N1, n2 m n3: move the content from line n1 to line n2 to line n3
: N1, n2 d: delete content from line n1 to line n2
: W: save the current file
: E filename: open the file filename and edit it.
: X: save the current file and exit.
: Q: Exit vi.
: Q! : Do not save the file and exit vi
:! Command: execute shell command
: N1, n2 w! Command: The content from line n1 to line n2 in the file is used as the command input and executed. if n1 and n2 are not specified, the entire file content is used as the command input.
: R! Command: place the output result of the command to the current line.
Register operation
"? Nyy: save the content of the current row and its n rows to the register? , Where? It is a letter, and n is a number.
"? Nyw: save the current row and its n characters to the register? , Where? It is a letter, and n is a number.
"? Nyl: save the current row and its n characters to the register? , Where? It is a letter, and n is a number.
"? P: retrieve the register? And place it at the cursor position. Here? It can be a letter or a number.
Ndd: delete n lines of text from the current row and its bottom, and put the deleted content in the delete register No. 1.