Vi (Visual Editor) Common commands, vieditor
Visual Editor is an effective and relatively simple full-screen editing tool that allows you to create and edit files, including documents, reports, and text, just remember a few basic commands, you can start and learn more
And the system administrator uses vi to manage and maintain the system.
Vi is the full-screen editing included in the SCO System V operating System. In fact, vi does not exist only in sco unix, but is quite popular in UNIX. You can use vi to enable a file, whether it is to enable a new file or modify an old file.
Format:
# Vi filename
If the file is new, a message is displayed at the bottom of the screen, telling the user that the new file is being created. If the file already exists, vi will display the first 24 lines of the file. You can use cursor to move the file.
This is the screen style after executing Vi:
~
~
The above is a simulated file opened by vi, and the twists and turns (~) at the beginning of a line (~) Indicates the end of the file. Vi uses two states: Command Mode and Insert Mode ). When vi is in the instruction state
It can be interpreted as an instruction. On the other hand, when vi is inserted in the Insert state, it can be written into the text to the file.
Most vi commands are single characters, changed from the Insert state to the command state, press the <Esc> key, and convert from the command state to the Insert state, you can use the following insert order to directly enter, you do not need to press the <Return> key.
L insert
I insert the body at the cursor
I insert the body at the beginning of a line
A append the body after the cursor
A. append the text at the end of A row.
O (lower case ou) opens a new row under the cursor
O (uppercase European) opens a new row on the cursor
Note that, in the Insert state, the command cannot be entered. you must press the <Esc> key to return the command state. If you do not know the state of your account, you can press the <Esc> key to return the command State regardless of the State.
L disk storage and logout
It is important to archive and exit a specified file when modifying a file. In vi, when executing an archived or exited command, you must first press the colon (:) to change to the command state. Then you can see the colon (:), show that vi has been changed
Can be archived or exited.
The following are some commonly used commands.
: Q! Exit vi by giving up any changes, that is, force exit.
: W Archive
: Wq archive and exit vi
: X works the same as wq.
: Zz and wq work the same way to delete the body
L Delete
Deleting or modifying the body uses the Insert state. Therefore, the commands mentioned below only need to be in the Insert state and directly select the command as the line.
X Character)
N characters after the nx cursor is deleted
NX Delete the first n characters at the cursor
Ndw deletes n words (word) at the cursor)
Dd deletes the entire row
D $ or D Delete the cursor to the end of the row
U is deleted before recovery.
L modify the body
When you use vi to modify the body and add or subtract characters, another group of commands in the Insert state will be used.
-R char uses char to replace the character at the cursor
-Rtext <Esc> uses text to replace the characters at the cursor.
-Cwtext <Esc> Replace the word at the cursor with text.
-Ctext <Esc>: the cursor is replaced by text to the end of the row.
-Cc makes the entire line blank, but retains the cursor position, so that you can start to enter
-Like deleting a command, the number of times that the command is run before the command is deleted.
L body mode Retrieval
To retrieve a file, it must be in the Command state. The so-called "Mode" is a specific string, which can contain space characters.
/Str <Return> Search for str forward until the end of the file
? Str <Return> Search for str until the start of the file
N duplicate searches in the Same Direction
N duplicate searches in the opposite direction
Vi wraps the entire file and searches continuously until the next occurrence that matches the pattern is found. If you want to switch to shell for execution during vi Execution, use the exclamation point (!) Run the command. For example, to list the contents of the current directory during the vi period, enter :!
If
On the other hand, you can create a. exrc environment file in the main directory and use set to input the option. Each time you call vi, the command and setting in. exrc will be read. The following is an example of the. exrc environment file:
Set wrapmarging = 8
Set showmode
Set autoindent
Set number