How to Use VI In Debian

Source: Internet
Author: User

1. VI Introduction

VI is a very common full-screen document editor in the Unix world. It can be said that almost any
All UNIX machines provide this set of software. There are also Linux. Its VI is actually Elvis.
(Copyright issues), but they are similar. After you are familiar with the file processing under DOS, you may
I feel that VI is not easy to use. Many updated and useful document editors have also been developed on UNIX.
But not every unix machine will install these additional software. So,
Learning the basic operations of VI is still advantageous, so that you can be comfortable on different machines.


2. Basic concepts of vi

UNIX provides a series of ex editors, including ex, edit, and VI. Compared with full-screen editing
It may be hard to imagine how to use the row and column Editor, such as ex and edit.
Is edlin attached before DOS 3.3 ?). VI is originally intended to be "visual", it is
The edited program that immediately responds, that is, you can view the operation result immediately.

Because VI is a full-screen editor, it must control the display of the entire terminal screen.
Something. There are many types of End-end machines with different features. Therefore, it is necessary for VI to know
Which type of End Server is used now. This is set by the TERM environment variable,
For more information about setting environment variables, see the shell description. (Unless
Should be unknow terminal type, otherwise you do not need to set .)

You can simply execute VI to enter the VI editing environment. Before the actual operation
A rough solution will be better. VI has two modes: input mode and command mode. Input
The command mode is used to input text materials, while the command mode is used to issue some orchestration files and store
File, and exit VI. After executing VI, the command mode is started.
Any element entered is considered as an instruction.


3. Access and exit

To enter Vi, you can directly enter VI <File Name> in the system prompt. Vi can automatically
Help you load the file you want to edit or open a new file. After entering VI, the left side of the screen will appear
The Tilde symbol. If this symbol is at the beginning of a column, it indicates that this column is currently empty. To exit Vi, you can
In command mode, if you type: Q, and: WQ, the command is archived and then left (note the colon ). To switch
In command mode, the [ESC] key is used. If you do not know the current mode, you can press
Several [ESC] times, the system will beep to confirm entering the command mode.


4. VI input mode

How do I enter materials? Several commands can enter the input mode:

Add (append)
A adds data from the end of the cursor. The data after the cursor is moved to the backend with the new data.
A adds data starting from the bottom of the column where the cursor is located.

Insert)
I. Data is inserted before the cursor position, and the data after the cursor is moved to the backend as new data is added.
I. Data is inserted before the first non-blank character in the column where the cursor is located.

Start (open)
O adds a column under the column where the cursor is located and enters the input mode.
O adds a new column to the column where the cursor is located and enters the input mode.

The text description may seem complicated, but you can understand it as soon as you operate it.
Operation Method. Practice is very important, especially computer things can be tried and verified at any time
Result. We strongly recommend that you use it instead of simply using K files to get twice the result with half the effort.
(Note: This section is nonsense .)


5. Basic VI editing

In combination with the function keys on the general keyboard, such as the direction keys, [insert], [delete], and so on.
You can use VI to process text. Of course, VI also provides many other
It makes text processing more convenient. If you are interested, please continue.

Click BCC before proceeding. Computers have many brands, different hardware and operating systems.
PCs are not just IBM PCs and Their compatible products. In fact, including the keyboard and terminal
And so on. What does this mean?

This problem may occur in the document editing software. Some computers do not have a few functions on their keyboards.
Key! So there are some functions that cannot be used? This problem is also the same in Unix systems, almost
Major computer manufacturers all have their own Unix systems, and the VI operation methods will also be somewhat different.
Although we can use the PC keyboard to explain the VI operation, we still need to raise this question.


Delete and modify

What is editing? Here we consider it as the addition, modification, and deletion of text, and even including text blocks.
Such as moving and re-partitioning. Here we will first introduce how to delete and modify VI. (Note:
In the original concept, input and editing are two things. Editing is performed in command mode.
The command moves the cursor to locate the location for editing, and then the command is edited .)

X deletes the character of the cursor.
Dd deletes the column where the cursor is located.
R: Modify the character of the cursor, and then modify the character of the cursor.
R enters the replacement status. The new data will overwrite the original data until you press [ESC] to return to the instruction mode.
.
S deletes the character of the cursor and enters 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 characters, simply press [delete. The insert and replace statuses are acceptable.
Directly use [insert] to switch between different commands. But just like before
As mentioned, these commands can be used on almost every terminal, rather than just on a PC.

In command mode, the basic commands for moving a cursor are H, J, K, and L. I think you should be able to guess now.
You only need to directly connect to the PC's direction keys, and both in command mode and input mode
Yes. Not easy.

Of course, the PC keyboard also has some shortcomings. There is a good command u to restore the deleted data, and
The U command restores all changes in the column where the cursor is located. This works with the [undo] buttons on some computers.
Can be the same.


6. Advanced VI Applications

I believe that we already have a considerable understanding of VI. It is not difficult to process text.
If you are interested in using other VI functions to further simplify the operation process, you may wish to continue looking at it.


Move cursor

Because many edits are located by the cursor, VI provides many ways to move the cursor.
Here are a few simple tables to illustrate (these are of course commands in the command mode ):

Certificate ----- certificate ------------- certificate ----- Certificate
│ Instruction │ description │ function key │
Certificate ----- certificate ------------- certificate ----- Certificate
│ 0 │ move to the front of the column where the cursor is located │ [home] │
Certificate ----- certificate ------------- certificate ----- Certificate
│ $ │ Move to the bottom of the column where the cursor is located │ [end] │
Certificate ----- certificate ------------- certificate ----- Certificate
│ [CTRL] [d] │ halfway down │

 

 

Certificate ----- certificate ------------- certificate ----- Certificate
│ [CTRL] [f] │ to the next page │ [Pagedown] │
Certificate ----- certificate ------------- certificate ----- Certificate
│ [CTRL] [u] │ up half page │
Certificate ----- certificate ------------- certificate ----- Certificate
│ [CTRL] [B] │ forward to previous page │ [Pageup] │
Certificate ----- certificate ------------- certificate ----- Certificate
Certificate -- certificate ----------------- Certificate
│ Instruction │ description │
Certificate -- certificate ----------------- Certificate
│ H │ move to the first column of the window │
Certificate -- certificate ----------------- Certificate
│ M │ move to the middle column of the window │
Certificate -- certificate ----------------- Certificate
│ L │ move to the last column of the window │
Certificate -- certificate ----------------- Certificate
│ B │ move to the first letter of the next word │
Certificate -- certificate ----------------- Certificate
│ W │ move to the first letter of the previous word │
Certificate -- certificate ----------------- Certificate
│ E │ move to the last letter of the next word │
Certificate -- certificate ----------------- Certificate
│ ^ │ Move to the first non-blank character in the column where the cursor is located │
Certificate -- certificate ----------------- Certificate
Certificate -- certificate ------------------- Certificate
│ Instruction │ description │
Certificate -- certificate ------------------- Certificate
│ N-│ minus signs move to the first non-blank character in the previous column │
│ You can specify to move the preceding n columns with numbers. │
Certificate -- certificate ------------------- Certificate
│ N + │ plus sign move to the first non-blank character in the next column │
│ Add a number to the front to specify to move to the following n columns │
Certificate -- certificate ------------------- Certificate
│ Ng │ directly use the number N plus the capital G to move to column N │
Certificate -- certificate ------------------- Certificate
Certificate ---- certificate --------------- Certificate
│ Instruction │ description │
Certificate ---- certificate --------------- Certificate
│ FX │ move to the right to x characters │
│ FX │ move to the left to X characters │
Certificate ---- certificate --------------- Certificate
│ TX │ move to the top right of X characters │
│ TX │ move to the left to the front of X characters │
Certificate ---- certificate --------------- Certificate
│; │ Use with F & T, repeat once │
│, │ Use with F & T, and repeat once in the opposite direction │
Certificate ---- certificate --------------- Certificate
│/String │ move to the right to a place with a string │
│? String │ move to the left to where a string exists │
Certificate ---- certificate --------------- Certificate
│ N │ /&? Use, repeat once │
│ N │ /&? Use, repeat once in the opposite direction │
Certificate ---- certificate --------------- Certificate
Certificate ---- certificate ------------------- certificate ---------- Certificate
│ Instruction │ description │ remarks │
Certificate ---- certificate ------------------- certificate ---------- Certificate
│ N (│ move the left parenthesis to the beginning of the sentence │ the sentence is │
│ You can move n sentences forward by adding numbers. │! .? Three symbols to define │
│ N) │ move the right brackets to the beginning of the next sentence │
│ Add a number to the front to specify to move n sentences to the back │
Certificate ---- certificate ------------------- certificate ---------- Certificate
│ N {│ move the left arc to the beginning of the paragraph │ the section is │
│ Add a number to the front to specify to move n paragraphs forward │ blank column definitions between paragraphs │
│ N} │ move the right arc to the beginning of the next section │

│ Add a number to the front to move n paragraphs to the back │
Certificate ---- certificate ------------------- certificate ---------- Certificate

Do not repeat these commands; otherwise, you are solely responsible. They look messy, fact
This is an obstacle in the text description. Once again, you only need to use it a few times.
These strange commands are far more powerful than rote memorization.
(Note: if the data is deleted by mistake without the brain
It has nothing to do with me. In addition, this section is nonsense .)


7. advanced editing commands

These editing commands are very flexible and basically consist of commands and scopes. For example, DW is
The deletion refers to the combination of D and 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. The cursor is located in the last letter of the word.
W cursor location to the first letter of the next word
B. The cursor is located at the first letter of the previous word.
$ Cursor location to the last letter in the column
0 cursor location to the first letter in the column
) Cursor location to the first letter of the next sentence
(The cursor is located at the first letter of the sentence.
} The cursor is located in the last letter of the paragraph.
{The cursor is located in the first letter of the paragraph.

To be honest, it is a little artistic to combine these commands to edit files. Whatever the case, they mention
For more compilation capabilities. It is worth noting that deletion and replication both apply the content within the specified range.
Put it in the temporary storage area, and then you can use the command P to paste it to other places. This is the VI used to process the partition
Copying and moving methods.

Some VI versions, such as Elvis for Linux, can greatly simplify this instruction. If it is slightly microscopic
When you check 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
Command. Command V is very easy to use. As long as you press the V key, the cursor location will be reversed. However
Then you can move the cursor.
Set the range, and then directly run the command to edit it.

For the entire column operation, VI also provides more convenient editing instructions. As mentioned earlier, deleting the entire column
Meaning that DD is one of them. CC can modify the entire text column, while YY can copy the entire text column;
Command D.
To delete all text from the cursor to the end of the column.


8. file commands

Archive commands start with:, which is a little different from editing commands. For example
Yes: Q.

Now I will briefly describe the end of this story:



: Q end editing (quit)
If you do not want to archive an archive and want to discard the edited archive, Use Q! Force exit.
: W archive (write)
The name of the file to be archived.
Archive commands can be combined. For example, WQ means archiving and leaving.
ZZ functions are the same as: WQ.

It is also worth mentioning that part of the VI archiving function. You can use: N, MW filename to column N to column M.
Column text is stored in the specified filename. The times are changing, the world is changing, and VI is also changing,
However, this is basically the case. Now, I hope the prince and the princess will live a happy and happy life.

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.