VI editor User Guide

Source: Internet
Author: User
Tags add numbers
Editor is an important tool for using computers. In various operating systems, editors are essential components. UNIX and similar IX Operating System series provide a series of ex editors, including ex, edit, Ed, and VI. ex, edit, and Ed are all row editors, which are rarely used now. The reason UNIX provides them is that they meet the needs of various users, especially some end users.

Fortunately, Unix provides a full-screen VI Editor, which makes our work much easier. Many dos users complain that the VI editor is not as easy as the edit editor in DOS, because VI takes into account the needs of various users, some general editing keys are not used (their definitions are different on different terminals, and they are not even used on some terminals ). The status switch method is used, but this is just a habit. Once you use VI skillfully, you will think it is actually very useful. Although VI uses the status switch method, there are a variety of computer hardware and operating systems, some computers do not have a few function keys on the keyboard! Isn't some functions unavailable? This problem is also the same in Unix systems. Almost all major computer manufacturers have their own Unix systems, and the VI operation methods will also be somewhat different. Here we use a PC keyboard to describe VI operations, but in the specific environment also need to refer to the relevant information, this is worth noting.

II. Introduction to VI

(1) Go to VI

In the system prompts (such as $, #), Type VI <File Name>, vi can automatically help you load the file to be edited or open a new file (if the file does not exist or the file name is missing ). After entering VI, A Tilde sign will appear on the left side of the screen. If this symbol is at the beginning of a column, it indicates that this column is currently empty.

(2) Two modes

As mentioned above, there are two modes in VI: Command mode and input mode. In command mode, keys entered are processed as commands. For example, if a is input, VI inserts a character at the current position. In the input mode, VI treats the Input key as the inserted character. To switch from the command mode to the input mode, you only need to enter the corresponding Input commands (such as A and A). to switch from the input mode to the command mode, you need to enter the ESC key in the input mode, if you do not know the current mode, you can press [ESC] several more times. If the system beeps, it indicates that it is in the command mode.

Pay: Instructions for entering the input mode in command mode:

Add (append)

A: add data from the end of the cursor. The data after the cursor is moved to the backend with the new data.

A: add data at the bottom of the column where the cursor is located.

Insert)

I: insert data from the front of the cursor. The data after the cursor moves to the back as the new data is added.

I: insert data starting from the first non-blank character in the column where the cursor is located.

Start (open)

O: Add a column under the column where the cursor is located and enter the input mode.

O: Add a new column to the column where the cursor is located and enter the input mode.

(3) Exit vi

In command mode, type: Q,: Q !, : WQ or: X (Note: No.), the VI will be exited. Where: WQ and: X are stored and exited, while Q is directly exited. If the file has a new change, VI will prompt you to save the file and the Q command will also be invalid, in this case, you can use the W command to save the file and then use Q to exit, or use the WQ or X command to exit. If you do not want to save the changed file, you need to use: q! Command to exit VI without saving the file.

(4) Basic editing

Use the function keys on the keyboard, such as the direction keys, [insert], and [delete]. Now you can use VI to edit files. Of course, VI also provides many other functions to facilitate text processing.

What is editing? It is generally regarded as the addition, modification and deletion of text, and even the moving and copying of text blocks. This section describes how to delete and modify VI. (Note: In the original concept of VI, input and editing are two things. Editing is performed in command mode. You can use the command to move the cursor to locate the place to be edited before editing the command .)

Command for deleting and modifying files:

X: Delete the character of the cursor.

DD: Delete the column where the cursor is located.

R: Modify the character where the cursor is located and the character to be corrected after R.

R: Enter the retrieval and replacement status. The new text will overwrite the original text until you press [ESC] to return to the command mode.

S: Delete the cursor character and enter the input mode.

S: Delete the column where the cursor is located and enter the input mode.

Actually, there is no such trouble on PC! Both input and edit operations can be completed in input mode. For example, if you want to delete a character, simply press [delete. The insert and replace statuses can be directly switched using [insert], making it impossible to edit commands in any command mode. However, as mentioned above, these commands can be used on almost every terminal, rather than just on a PC.
In command mode, the basic commands for moving the cursor are H, J, K, and L. I think you should be able to guess that you only need to use the direction keys of the PC, and you can use them either in the command mode or in the input mode. Not easy.
Of course, the PC keyboard also has some shortcomings. The command u can be used to restore deleted text, while the command u can restore all changes in the column where the cursor is located. This is the same as the [undo] button function on some computers.
Iii. Attachment: VI detailed instruction table
(1) Basic editing commands:
Add (append)

A: add data from the end of the cursor. The data after the cursor is moved to the backend with the new data.

A: add data at the bottom of the column where the cursor is located.

Insert)

I: insert data from the front of the cursor. The data after the cursor moves to the back as the new data is added.

I: insert data starting from the first non-blank character in the column where the cursor is located.

Start (open)

O: Add a column under the column where the cursor is located and enter the input mode.

O: Add a new column to the column where the cursor is located and enter the input mode.

X: Delete the character of the cursor.

DD: Delete the column where the cursor is located.

R: Modify the character where the cursor is located and the character to be corrected after R.

R: Enter the retrieval and replacement status. The new text will overwrite the original text until you press [ESC] to return to the command mode.

S: Delete the cursor character and enter the input mode.

S: Delete the column where the cursor is located and enter the input mode.

(2) cursor movement instructions:
Because a lot of editing work is positioned by the cursor, VI provides a lot of ways to move the cursor.
Several simple tables to illustrate (these are of course commands in the command mode ):

Command description function key
0 move to the front of the column where the cursor is located [home]
$ Move to the last [end] of the column where the cursor is located
[CTRL] [d] half a page [Pagedown]
[CTRL] [f] to the next page
[CTRL] [u] up half page
[CTRL] [B] [Pageup]

Instructions
H move to the first column of the window
M moves to the middle column of the window
L move to the last column of the window
B Move to the first letter of the next word
W move to the first letter of the previous word
E. Move to the last letter of the next word.
^ Move the first non-blank character to the column where the cursor is located

Instructions
N-Minus signs move to the first non-blank character in the previous column plus a number can be specified to move to the N column above
N + plus signs move to the first non-blank character in the next column plus a number can be specified to move to the following n columns
Ng directly uses the number N plus the capital G to move to column N
Instructions
FX
Move to the right to x characters
Move FX to the left to X characters
TX to the right before X
TX moves to the left before X characters
; Used with F & T, repeat once
, Used in combination with F & T, repeat once in the opposite direction
/Move the string to the right to a place with a string
? Move string to the left to a place with a string
N combination /&? Use, repeat once
N combination /&? Used, repeated in the opposite direction

Instructions
N (
Move the left parenthesis to the beginning of the sentence. The sentence is preceded by a number and can be specified to move n sentences forward! .? Three symbols to define
N) You can move the brackets to the beginning of the next sentence and add numbers to move n sentences to the end! .? Three symbols to define
N {move the left arc to the beginning of a paragraph. The Section is defined by a blank column between paragraphs.
N} You can move n paragraphs forward, right arc, to the beginning of the next paragraph, and add a number to the beginning of the next paragraph. You can move n paragraphs backward, which is defined by the blank columns between paragraphs.

(3) More editing commands
These editing commands are very flexible and basically consist of commands and scopes. For example, DW is composed of the DELETE command D and the range W, which means to delete a word D (elete) W (ORD ).
The command list is as follows:
D. Delete)
Y replication (Yank)
P placement (Put)
C Change)
The range can be:
E? BR> W cursor position to the first letter of the next word
B. Place the cursor on the first letter of the last word.
$ Move the cursor to the last letter in the column
0 cursor position to the first letter in the column
) Place the cursor to the first letter in the next sentence.
(The cursor is located at the first letter in the sentence.
} Move the cursor to the last letter of the paragraph
{Place the cursor in the first letter of the paragraph
To be honest, it is a little artistic to combine these commands to edit files. In any case, they provide more text editing capabilities. It is worth noting that the deletion and replication will put the content within the specified range in the temporary storage area, and then the instruction P can be used to paste it to other places, this is how VI processes copying and moving segments.
Some VI versions, such as Elvis for Linux, can greatly simplify this instruction. If you take a look at these editing commands, you will find that the problem is actually a bit complicated by the fixed range method. In fact, there are only four commands. Command V is very easy to use. As long as you press the V key, the position of the cursor will be reversed. Then, you can move the cursor to set the range, and then directly edit the command. For the entire column operation, VI also provides more convenient editing instructions. As mentioned above, the command DD for deleting the entire text column is one of them. CC can modify the entire text column, while YY is to copy the entire text column; command D deletes all text from the cursor until the end of the column.
(4) file operation commands
File Operation commands start with:, which is a little different from editing commands.
: Q end editing (quit)
: Q! You must discard edited files without archiving them.
: W: Save the file (write) and add the file name to be archived.
: WQ indicates that the archive is removed.
ZZ functions are the same as: WQ.
: X is the same as: WQ
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.