/Folder in the root directory
Enter "/" and press ENTER
There are many folders, such as etc, home, Lib, MNT, etc.
ETC: stores the user name and password
Home: each user has a folder, which is stored here.
Lib: operating system files
MNT: used for hook-up
OPT: Java Tool
BEA: Something about Web Programming
Sbin, bin, USR: these three folders all store Unix commands.
TMP: Temporary Folder
Common Operations:
View the current directory: pwd
Change Password: passwd
Switch Mode: CSH, bash
Remote login: Telnet Server IP Address
Go back to the parent directory: CD ..
View the folder in this directory: ls
Open File: VI/folder/File
File display format: Root: X: 0: Root... :/Root;/bin/bash user name, encryption, serial number, group, default path
Exit: esc shift +: Q! Quit exit
Clear: Clear
Show all files in the current directory: ls-
Show all files and details in the current directory: ls-Al
New File: VI file name
File Permission: chmod g-(+) R w x u g o s
Create a new file (cannot be edited) Update the file access time. If there is a file, update, does not exist, create: Touch file name
Create directory: mkdir directory name/directory name
Create multiple directories: mkdir directory name .....
Create a directory in the main directory: mkdir ~ /Directory name
Create a multilevel Directory: mkdir-P directory name/directory name
Make a prompt before overwriting the file: CP-I
Copy between file and file content: CP
Copy Directory: CP-r directory
Copy a file: CP File
Move file: the directory to which the MV file is to be moved
Move Directory: the directory to which MV-Fi is to be moved
Modify the name of a file or directory: MV file name
Delete file: Rm-I Prompt
Delete all contents in the directory, including the directory to be deleted by RM-R.
Connection: soft connection: equivalent to creating a shortcut. function: Modify the Linux kernel to use the in
Hard connection: if the source file is deleted, the content of the connected file still exists.
Help: Man command
Completion name: Table
Show Calendar: Cal
Input:>
Output: <
View File Content: cat Example: CAT <File> File
Split-screen display: ls-L/directory | more
Merge to a new file: CAT a.txt B .txt
Set environment variables:
CSH. cshrc source cshrc
Execute. profile or source. Profile in bash.
This editor is the most commonly used tool in all computer systems. In UNIX, the editors include ex, sed, and VI. Among them, VI is the most widely used, while VI commands are numerous. The Forum does not seem to have a summary of this. The following is a summary, share resources! Eager to correct and supplement!
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 one by one.
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: (Note the number is zero) 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; open a screen at 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.
**************************************** **********************************
The second person's
**************************************** ********************************
Text Editor vi
VI is a universal full-screen text editor in the Unix world. Vim is short for its improved version VI improved. Almost any unix machine provides this software. There are also Linux. Its VI is actually ELVIS (copyright issues), but they are similar. After being familiar with the file processing under DOS, you may feel that VI is not easy to use. On UNIX, many newer and more useful file editors have been developed, however, these additional software may not be installed on every unix machine. Therefore, it is good to learn the basic operations of VI, so that you can be handy on different machines.
VI concepts
UNIX provides a series of ex editors, including ex, edit, and VI. Compared with the full screen editor, it is difficult to imagine how to use the row and column editor such as ex and edit. VI is originally intended to be "visual", which is an edited response immediately Program That is to say, you can see the operation result immediately.
Because VI is a full-screen editor, it must control the display of the entire terminal screen. There are many types of terminals with different features. Therefore, it is necessary for VI to know which terminal is used now. This is set by the TERM environment variable. for setting the environment variable, see the description of the shell used.
You can simply execute VI in shell to enter the VI editing environment. It is better to understand it before you perform the actual operation. VI has two modes: input mode and command mode. The input mode is used to input text materials, while the command mode is used to issue operation instructions for some orchestration files, archives, and exit VI. After executing the VI command, the command mode is started. At this time, any words entered are considered as commands. For detailed operations on VI, refer to the relevant UNIX tutorial.
VI history
1. The birth of vi
VI was written by Bill Joy, who was still in Berkeley. Ken Thompson took his incomplete Pascal system when he went to Berkeley, and Bill Joy just got a job to fix it during the summer vacation, and he fixed it. Code The editor Ed is not satisfied. Exactly. They got em code from a guy named George coulouris, which is better than Ed. They modified em, invented en, and eventually changed to ex (even Bill Joy did not know how to change to ex ). Later, he spent a few months and wrote VI.
2. VI was not written over a weekend.
Bill Joy himself claims that he has spent a lot of time, but it does not seem to be because of how hard it is to write, but because of Bill's very slow modem, which only has 300 Potter.
Common VI skills
The VI command is the most commonly used file editing command in the Unix/Linux World, but many people are not used to it because of its many command sets, in fact, you only need to master the basic commands and use them flexibly. Then you will find its advantages and will gradually enjoy using this method. This article aims to introduce some of the most common commands and advanced application skills of VI.
1. Introduction to basic commands
---- 1. cursor command
K, J, H, l -- move the cursor up, down, left, and right. Although you can use the four optical keys on the right of the keyboard in Linux, it is very useful to remember these four commands. These four keys are the basic locations where the right hand is placed on the keyboard.
Ng -- jump command. N indicates the number of rows. This command immediately redirects the cursor to the specified row.
CTRL + G -- number of rows and columns at the cursor position.
W, B -- let the cursor skip a word forward or backward.
---- 2. Edit the command
I, A, R -- insert character commands (I = insert, A = append, r = replace) before, after, and at the cursor ).
CW, DW -- change (replace)/command for deleting words where the cursor is located (C = change, D = delete ).
X, d $, and DD -- delete a character, delete all characters from the cursor's position to the end of the line, and delete the entire line.
---- 3. Search for commands
----/String ,? String -- the command used to search for the corresponding string from the cursor to the back or forward position.
---- 4. copy Copy command
---- YY, p -- command used to copy a row to the clipboard or retrieve the content in the clipboard.
Ii. FAQs and application skills
---- 1. Read the content in/etc/passwd in a new file and retrieve the username section.
---- VI File
----: R/etc/passwd read/etc/passwd at the cursor position in the opened file
----: % S/:. * // G delete all parts after the user name in/etc/passwd from the colon until the end of the line.
---- You can also read the file content after the specified row number. For example, you can use the command ": 3R/etc/passwd" to read all the content of/etc/passwd from line 1 of the new file.
---- You can also use the following method to delete all blank lines in the file and comment lines starting.
---- # Cat squid. conf. Default | grep-V ^ $ | grep-V ^ #
---- 2. After opening a file and editing it, the logged-on user does not have the write permission for the file and cannot store the disk. You need to save the modifications to the temporary file.
---- VI File
----: W/tmp/1 save all the modifications you have made. You can also save some of the modifications to a temporary file. For example, you can only save 20th ~ Store the contents between 59 rows into a file/tmp/1. You can type the following command.
---- VI File
----: 20, 59 w/tmp/1
---- 3. Use VI to edit a file, but you need to delete the contents of a large segment.
---- Use the edit command "VI file" to open the file, move the cursor to the row to be deleted, press Ctrl + G to display the row number, and then press Ctrl + G to the end, displays the row number at the end of the file.
----: Assume that the number of rows obtained twice in 23,104 5d is 23 and 1045, all contents in this period will be deleted, you can also mark the start and end lines to be deleted with the MA and MB commands, and then use the ": A, BD" command to delete them.
---- 4. Add strings at the beginning or end of the row or several lines of the entire file.
---- VI File
----: 3, $ S/^/some string/Insert "some string" at the beginning of the line from the first row to the last row of the file ".
---- % S/$/some string/g Add "some string" at the end of each row of the entire file ".
---- % S/string1/string2/g Replace "string1" with "string2" in the entire file ".
----: 3rd S/string1/string2/Replace "string1" in rows 7th to of the file with "string2 ".
---- Note: S is substitute, % indicates all rows, and G indicates global.
---- 5. Edit two files at the same time, copy the text in one file and paste it into another file.
---- VI file1 file2
---- YY copies the row at the cursor of file 1
----: N switch to file 2 (n = NEXT)
---- P paste the copied row at the cursor of file 2
----: N switch back to file 1
---- 6. Replace the path in the file.
---- Use the command ": % s #/usr/bin # G" to replace all the paths/usr/bin in the file with/bin. You can also run the command ": % S/usr/bin // bin/g", where "" is an escape character, it indicates that the subsequent "/" character is a meaningful character, not a separator.
VI editor commands in Linux
Enter "/" and press ENTER
There are many folders, such as etc, home, Lib, MNT, etc.
ETC: stores the user name and password
Home: each user has a folder, which is stored here.
Lib: operating system files
MNT: used for hook-up
OPT: Java Tool
BEA: Something about Web Programming
Sbin, bin, USR: these three folders all store Unix commands.
TMP: Temporary Folder
Common Operations:
View the current directory: pwd
Change Password: passwd
Switch Mode: CSH, bash
Remote login: Telnet Server IP Address
Go back to the parent directory: CD ..
View the folder in this directory: ls
Open File: VI/folder/File
File display format: Root: X: 0: Root... :/Root;/bin/bash user name, encryption, serial number, group, default path
Exit: esc shift +: Q! Quit exit
Clear: Clear
Show all files in the current directory: ls-
Show all files and details in the current directory: ls-Al
New File: VI file name
File Permission: chmod g-(+) R w x u g o s
Create a new file (cannot be edited) Update the file access time. If there is a file, update, does not exist, create: Touch file name
Create directory: mkdir directory name/directory name
Create multiple directories: mkdir directory name .....
Create a directory in the main directory: mkdir ~ /Directory name
Create a multilevel Directory: mkdir-P directory name/directory name
Make a prompt before overwriting the file: CP-I
Copy between file and file content: CP
Copy Directory: CP-r directory
Copy a file: CP File
Move file: the directory to which the MV file is to be moved
Move Directory: the directory to which MV-Fi is to be moved
Modify the name of a file or directory: MV file name
Delete file: Rm-I Prompt
Delete all contents in the directory, including the directory to be deleted by RM-R.
Connection: soft connection: equivalent to creating a shortcut. function: Modify the Linux kernel to use the in
Hard connection: if the source file is deleted, the content of the connected file still exists.
Help: Man command
Completion name: Table
Show Calendar: Cal
Input:>
Output: <
View File Content: cat Example: CAT File
Split-screen display: ls-L/directory | more
Merge to a new file: CAT a.txt B .txt
Set environment variables:
CSH. cshrc source cshrc
Execute. profile or source. Profile in bash.
This editor is the most commonly used tool in all computer systems. In UNIX, the editors include ex, sed, and VI. Among them, VI is the most widely used, while VI commands are numerous. The Forum does not seem to have a summary of this. The following is a summary, share resources! Eager to correct and supplement!
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 one by one.
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: (Note the number is zero) 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 to the first part of the file [Up]
CTRL + D: Flip the half screen to the end of the file [Down]
CTRL + F: Turn a screen at the end of the file [Front]
CTRL + B: Flip the screen to the beginning of the file [back]
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.
**************************************** ***************************
The third person's
**************************************** ****************************
The VI editor is a standard editor for all UNIX and Linux systems. It is not inferior to any of the latest text editors. Here we just briefly introduce its usage and a few instructions. The VI editor is identical for any version of UNIX and Linux systems, so you can learn more about it in any other section about VI. VI is also the most basic text editor in Linux. Once you learn it, you will be able to access it freely in the Linux World.
1. Basic concepts of vi
Basically, VI can be divided into three states: Command mode, insert mode, and last line mode. The functions of each mode are as follows:
1) Command Line Mode)
Controls the movement of the screen cursor, the deletion of characters, words, or rows, the movement of copying a segment and entering the insert mode, or to the last line mode.
2) insert mode)
You can enter text only in insert mode. Press ESC to return to command line mode.
3) Baseline Mode)
Save the file or exit VI. You can also set the editing environment, such as searching strings and listing row numbers ...... .
However, we generally simplify VI into two modes in use, that is, the last line mode is also included in the command line mode ).
2. Basic operations of vi
A) Go to VI
After the system prompts you to enter the VI and file name, you will be taken to the VI full screen editing screen:
$ VI myfile
Note that after entering Vi, you are in command mode. You must switch to insert mode to Enter text. People who use VI for the first time will want to move the cursor first with the upper and lower right keys. As a result, the computer keeps beeping and getting angry with themselves. So after entering VI, do not tamper with the mouse, switch to "insert mode!
B) switch to insert mode to edit the file
Click "I" under "command mode" to enter "insert mode". Then, you can enter the text.
C) Insert switchover
You are currently in "insert mode", and you can only enter text all the time. If you find that you have entered an error! To move the word back with the light mark key, you must first Press ESC to switch to command mode and then delete the text.
D) Exit VI and save the file
Under "command mode", click ":" colon to enter "last line mode". For example:
: W filename (enter "w filename" Article Save with the specified filename)
: WQ (enter "WQ" to save the disk and exit VI)
: Q! (Enter Q !, Force exit VI without saving the disk)
3. Command mode function key
1). insert mode
Press "I" to switch to the insert mode "insert mode". Press "I" to enter the insert mode. The input file starts from the current position of the cursor;
After you press "a" to enter the insert mode, the text is entered starting from the next position where the cursor is currently located;
After you press "O" to enter the insert mode, a new row is inserted and text is entered from the beginning of the line.
2) switch from insert mode to Command Line Mode
Press ESC.
3) move the cursor
VI can be moved up, down, left, and right directly with the cursor on the keyboard, but the regular VI uses lowercase letters "H", "J", "K", and "L 」, the cursor is controlled to move one cell to the left, down, up, and right respectively.
Press Ctrl + B to move the screen to the back.
Press Ctrl + F to move the screen to the front.
Press Ctrl + u to move the screen to the back half of the page.
Press Ctrl + D to move the screen half to the front.
Press the number "0": to move to the beginning of the article.
Press g to move to the end of the article.
Press "$" to move to the end of the row where the cursor is located ".
Press ^ to move the cursor to the beginning of the row"
Press W to jump to the beginning of the next word
Press "E": move the cursor to the end of the next word
Press "B": the cursor returns to the beginning of the previous word
Press # l to move the cursor to the # position of the row, such as 5l and 56l.
4). delete text
"X": each time you press the button, the "Next" character of the cursor is deleted.
"# X": for example, "6x" indicates deleting the "Next" 6 Characters of the cursor position.
"X": uppercase X. Each time you press it, the "front" character of the cursor is deleted.
"# X": for example, "20x" indicates the position where the cursor is located, which is a string of 20 characters.
DD: Delete the row where the cursor is located.
「 # Dd 」: delete from the row where the cursor is located # Row
5). Copy
"Yw": copy the character at the end of the cursor to the buffer zone.
# YW: Copy # words to the buffer zone
"YY": copy the row where the cursor is located to the buffer zone.
"# YY": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down.
P: place the characters in the buffer to the cursor position. Note: All copy commands related to "Y" must work with "P" to complete the copy and paste function.
6). Replace
"R": Replace the character at the cursor position.
"R": Replace the character wherever the cursor goes until you press the "ESC" key.
7). Reply to the previous operation
"U": If you mistakenly execute a command, you can immediately press "U" to return to the previous operation. You can perform multiple replies Based on Multiple "U" requests.
8). Change
"CW": change the word at the cursor to the ending point.
"C # W": for example, "c3w" indicates that three words are changed.
9). Jump to the specified row
CTRL + G lists the row numbers of the cursor.
"# G": for example, "15g" indicates moving the cursor to the first row of the article.
4. Introduction to commands in last line mode
Before using "last line mode", remember to press the "ESC" key to confirm that you are already in "command mode" and then press 「: "colon to enter" last line mode 」.
A) List row numbers
"Set nu": After "set nu" is entered, the row number is listed before each row in the file.
B) jump to a row in the file.
"#": "#" Indicates a number. Enter a number after the colon and press enter to jump to the row. For example, enter the number 15 and press Enter, this will jump to the second line of the article.
C) Search for characters
"/Keyword": First press the "/" key and then enter the character you want to search. If the first search keyword is not what you want, you can always press "N" until you find the keyword you want.
「? Keyword: First press 「?」 Enter the character you want to search for. If the keyword you want for the first time is not what you want, you can press "N" until you find the keyword you want.
D) save the file
"W": Enter "W" in the colon to save the file.
E) Leave Vi
Q: Press Q to exit. If you cannot exit Vi, you can follow Q with 「!」 Force exit VI.
"QW": it is generally recommended to use it with "W" when leaving, so that files can be saved when exiting.
5. VI command list
1. The following table lists some key functions in command mode:
H
Move the cursor one character left
L
Move the cursor one character to the right
K
Move the cursor up a row
J
Move the cursor down a row
^
Move the cursor to the beginning of the line
0
Number "0", move the cursor to the beginning of the article
G
Move cursor to the end of the article
$
Move the cursor to the end of the row
CTRL + F
Forward screen flip
CTRL + B
Flip back
CTRL + d
Front Half Screen
CTRL + u
Flip back half screen
I
Insert characters before the cursor position
A
Add the next character at the cursor position
O
Insert a new row and start from the beginning of the row.
ESC
Return from input to command status
X
Delete characters after the cursor
# X
# Characters After deleting the cursor
X
(Uppercase X), delete the character before the cursor
# X
Delete # characters before the cursor
Dd
Delete the row where the cursor is located
# Dd
Delete # rows from the number of rows where the cursor is located
YW
Copy a word at the cursor position
# YW
Copy the # characters at the cursor position
YY
Copy a line at the cursor position
# YY
Copy the number of rows from the cursor
P
Paste
U
Cancel operation
CW
Change the cursor position.
# CW
# Words for changing the cursor position
2. Some commands in the following Table travel command mode
W filename
Save the file being edited as filename
WQ filename
Save the file being edited as filename and exit vi
Q!
Discard all modifications and exit vi
Set nu
Show row number
/Or?
Search, enter the content to search after/
N
And/or? If the search content is not the keyword, press N or backward (and/) or forward (and? Continue searching until it is found.
Note the following when using VI for the first time:
1. After opening a file with VI, it is in command mode. You must switch to insert mode to Enter text. Switch method: click "I" under "command mode" to enter "insert mode )」, now you can start to input text.
2. After editing, you must switch from the insert mode to the command line mode to save the file. to switch to the mode, Press ESC.
3. Save and exit the file: In command mode, enter WQ! (Don't forget the one before WQ :)