Unix Linux General VI command, using the Help Manual "Collector's Edition"

Source: Internet
Author: User

About Vi

Vi is the most popular full-screen document editor in the Unix world, and almost any UNIX machine can say
will provide this software. Linux Of course also has, its VI is actually Elvis (copyright question), but they all
Almost. Familiar with the DOS of the document processing, may feel that VI is not good, Unix has developed
Many newer, better-used clerical editors, but not necessarily every Unix machine will install these additional
of software. Therefore, the basic operation of Learning VI is still a good thing, let you in various machines handy.


Vi Basic Concepts

Unix offers a range of ex editors, including ex, Edit and VI. Relative to the full screen editor, now
It may be hard to imagine how to use EX, edit this column editor (someone has used a DOS version 3.3 previously attached
EDLIN? )。 Vi is originally intended to be "Visual," an editor that responds immediately, which means
To see the results of the operation immediately.

Also because VI is a full-screen editor, it has to control what is displayed on the entire terminal screen. and finally
There are many kinds of end-machine, the characteristics are not the same, so VI need to know what kind of end is used now
End Machine. This is set by the term of this environment variable, set the environment variables to see the use of the shell
The description. (unless the Unknow terminal type is responded to when VI is executed, it can be used without setting.) )

As long as the simple implementation of VI can enter the VI editing environment. There's a rough outline of it before you actually do it.
The solution will be better. Vi has two modes, input mode and instruction mode. Input mode is used to enter text
The instruction mode is used to release some of the instructions for arranging files, archiving, and leaving VI, and so on. When
When you execute VI, the instruction mode is entered, and any characters you enter are treated as instructions.


Enter and leave

To enter VI can be directly under the system prompt type VI file name >,VI can automatically help you load
The file you want to edit or open a new file. After entering VI, there will be a wave symbol on the left of the screen.
The symbol indicates that the column is currently empty. To leave VI you can type in instruction mode: Q,: the WQ command is
Archive and leave (note the colon). To switch to instruction mode, use the [ESC] key, if you don't know now
is in what mode, you can press more than a few times [ESC], the system will beep to determine the mode of entry instructions.


Vi Input Mode

How do you enter data? There are several instructions to enter the input mode:

New (Append)
A new data is started from the back of the cursor, and the data behind the cursor moves with the new data.
A new data is started from the end of the column where the cursor is located.

Inserting (insert)
I insert the data from the front of the cursor, and the data after the cursor moves with the new data.
I Insert the data before the first non-whitespace character in the column where the cursor is located.

Start (Open)
o Add a new column under the Cursor column and enter the input mode.
O add a column above the cursor column and enter the input mode.

The narrative may seem a little complicated, but you can see how it works as soon as you actually do it. Real
is important, especially when it is possible to try and verify the results of computer-related things. It is highly recommended to actually use it and
Do not just the K file, only a multiplier effect. (Note: This paragraph is nonsense.) )


Vi Basic Editing

With the function keys on the general keyboard, such as the arrow keys, [Insert], [Delete] and so on, now you should have
can use VI to deal with the text material. Of course VI also provides many other functions to make the text processing more shape
Convenient, interested to see Hostler please continue.

Let's have BCC before we go on. Computers have many cards, different hardware and operating systems. Nor is the PC
Only IBM PCs and their compatible products. In fact, including keyboards, terminals and so on often have different rules
Pane What does this mean?

On the document editing software will encounter such problems, some computer keyboard does not have a specific number of function keys! So no
There are some features that can't be used? This is the same problem on Unix systems, and almost every major computer manufacturer has its own
Unix system, and Vi's method of operation will be somewhat out of the way. Of course, we can use the PC's keyboard
The operation of the Ming VI, but still have to mention this problem.


Delete and modify

What is editing? In this case, we consider the addition and deletion of the text, even the moving and re-
System and so on. Here first introduce VI how to do delete and modify. (Note: In the original concept of VI, the input and
The editor is two things. The edit is operated in instruction mode, and the cursor is positioned to be edited using the instruction movement
Place, and then make an order for editing. )

x Delete the character that is located in the cursor.
DD deletes the column where the cursor resides.
R modifies the character of the cursor, and R is followed by the character to be corrected.
R enters the replacement state and the new data overwrites the original data until you press [ESC] back to instruction mode.
s deletes the character of the cursor and enters the input mode.
S deletes the column where the cursor is located and enters input mode.

In fact, there is no such trouble at all on the PC! Both the input and the edit can be done in input mode. For example, to delete
In addition to the characters, press [Delete] directly. The insert state and the substitution state can be cut directly with [insert]
The editing instructions for the instruction mode. But as mentioned earlier, these instructions are almost every
Terminals can be used, not just on the PC.

The basic instructions for moving a cursor in instruction mode are H, J, K, L. I think you should be able to guess now, as long as straight
The key of the PC is OK, and it can be used in both instruction mode and input mode. How easy it is not.

Of course, the PC keyboard also has shortcomings. There is a very good command u can recover deleted data, and U instruction
You can restore all changes to the column where the cursor is located. This is the same as the [Undo] key function on some computers.


Vi Advanced Applications

I believe that the VI should have a considerable understanding of the present. There is no trouble in dealing with words. If there is a hing
Use the other functions of VI to further simplify the operation, you may wish to continue to watch.


Moving cursors

Because many editing jobs are positioned by cursors, VI provides many ways to move cursors, which we
A few short tables to illustrate (these are, of course, instructions in instruction mode):

┌ ————— ┬ ————————————— ┬ ————— ┐
│ Instruction │ Description │ function key │
├ ————— ┼ ————————————— ┼ ————— ┤
│0│ moves to the front of the column where the cursor is located │[home]│
├ ————— ┼ ————————————— ┼ ————— ┤
│$│ moves to the last face of the column in which the cursor is located │[end]│
├ ————— ┼ ————————————— ┼ ————— ┤
│[ctrl][d]│ down half page ││
├ ————— ┼ ————————————— ┼ ————— ┤
│[ctrl][f]│ down one page │[pagedown]│
├ ————— ┼ ————————————— ┼ ————— ┤
│[ctrl][u]│ up Half page ││
├ ————— ┼ ————————————— ┼ ————— ┤
│[ctrl][b]│ up one page │[pageup]│
└ ————— ┴ ————————————— ┴ ————— ┘
┌--┬ ————————————————— ┐
│ Instruction │ Description │
├--┼ ————————————————— ┤
│h│ move to the first column of Windows │
├--┼ ————————————————— ┤
│m│ move 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 last word │
├--┼ ————————————————— ┤
│e│ move to the last letter of the next word │
├--┼ ————————————————— ┤
│^│ move to the first non-whitespace character in the column where the cursor is located │
└--┴ ————————————————— ┘
┌--┬ ——————————————————— ┐
│ Instruction │ Description │
├--┼ ——————————————————— ┤
│n-│ minus sign moves to the first non-whitespace character in the previous column │
││ Front plus number can be specified to move to the N column above │
├--┼ ——————————————————— ┤
│n+│ plus moves to the first non-whitespace character in the next column │
││ Front plus number can be specified to move to the following n columns │
├--┼ ——————————————————— ┤
│ng│ directly with the number n plus the upper case G to nth column │
└--┴ ——————————————————— ┘
┌ ———— ┬ ——————————————— ┐
│ Instruction │ Description │
├ ———— ┼ ——————————————— ┤
│fx│ move right to X-characters │
│fx│ move left to x characters │
├ ———— ┼ ——————————————— ┤
│tx│ move right to the X-character before │
│tx│ move left to X-character │
├ ———— ┼ ——————————————— ┤
│ │ cooperate with f&t, repeat once │
│,│ with f&t use, the opposition to repeat once │
├ ———— ┼ ——————————————— ┤
│/string│ move right to the place with string │
│?string│ move left to the place with string │
├ ———— ┼ ——————————————— ┤
│n│ with/&? Use, repeat once │
│n│ with/&? Use, opposite to repeat once │
└ ———— ┴ ——————————————— ┘
┌ ———— ┬ ——————————————————— ┬ —————————— ┐
│ Instructions │ Instructions │ Remarks │
├ ———— ┼ ——————————————————— ┼ —————————— ┤
│n (│ left parenthesis move to the front of the sentence │ the sentence is to │
││ Front plus number can be specified to move the n sentence forward │!. ? Three kinds of symbols to define │
│n) │ Right parenthesis move to the front of the next sentence ││
││ Front plus number can be specified to move n sentences ││
├ ———— ┼ ——————————————————— ┼ —————————— ┤
│n{│ left bracket moves to the front of the paragraph │ paragraph is to │
││ Front Plus number you can specify to move forward n paragraphs │ blank column boundaries between paragraphs │
│n}│ right parenthesis moves to the front of the next paragraph ││
││ Front plus number can be specified to move n paragraphs ││
└ ———— ┴ ——————————————————— ┴ —————————— ┘

Do not attempt to recite these instructions, or you will be responsible for your own consequences. They look so messy and they're actually words
An impediment to the narrative itself. Once again, the actual use of it can only a few times without the brain directly release these odd
Strange instructions, far more than the rote live back to make a much more vague. (Note: If you do not accidentally delete the data through the brain
Nothing to do with me. Another, this paragraph is nonsense. )


Advanced editing Instructions

These editing instructions are very resilient and basically consist of directives and scopes. For example, DW is deleted by means of the
Make d with the range W, representing the deletion of a word D (elete) W (ORD).

The instruction list is as follows:

D Remove (delete)
Y copy (Yank)
P Placement (put)
C Modification (change)

The range can be a few of the following:

e cursor position to the last letter of the word
W cursor position to the first letter of the next word
b cursor position to the first letter of the previous word
$ cursor position to the last letter of the column
0 cursor position to the first letter of the column
) cursor position to the first letter of the next sentence
(The cursor is in the same position as the first letter of the sentence
The cursor is located to the last letter of the paragraph
{The cursor is in the same position as the first letter of the paragraph

To be honest, combining these instructions to edit the file has a little bit of artistic flair. Anyway, they offer more
The ability to edit text. It is important to note that both delete and copy will place the contents of the specified range in the staging area,
Then you can use the command p to post to other places, which is VI to deal with section copy and move the method.

Some vi versions, such as the Elvis used by Linux, can greatly simplify this lump of instructions. If you look a little
These editing instructions will find that the problem is actually fixed range of the way a little miscellaneous, actually only four instructions.
Command V is very easy to use, as long as you press the V key, the cursor position will be reversed, then you can move the cursor to
Set the range, then directly under the command to edit.

For the whole column operation, VI also provides more convenient editing instructions. The previous mention of deleting the entire column of text refers to the
DD is one of them, CC can modify the whole column of text, while YY is to copy the whole column of text, instruction D can be
To delete the cursor until the end of the column.


File Instructions

File instructions to: Beginning, with the editing instructions a little different. For example, the previous instruction to end the edit is: Q.
Let's briefly explain the end of the story as follows:

: Q End Edit (quit)
To discard an edited file if you do not want to archive it by: q! Forced to leave.
: W Archive (write)
You can then add the file name you want to archive.
File instructions can be combined, for example: Wq is archived and then left.
The ZZ function is the same as: Wq.

Also worth mentioning is the partial archiving function of VI. Can be used: N,MW filename to row N to line M
The text is stored in the specified filename. Times are changing, the world is changing, vi is changing, but big
That's it. Well, I hope the Prince and the Princess have a happy life.

Unix Linux General VI command, using the Help Manual "Collector's Edition"

Related Article

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.