Use of VI in UNIX

xiaoxiao2021-03-30  216

Line number in VI

Many of the commands in the VI uses values ​​such as line numbers and rows. If the edited file is large, you can go to the number of yourself is very inconvenient. To this end, VI provides a function of adding a trine number to a text. These line numbers are displayed on the left of the screen, while the contents of the corresponding row are displayed behind the line number.

The command used is: Enter the command in the last mode:

: set Number

It should be noted that the line number added here is only displayed to the user, which is not part of the file content.

In a large file, the user may need to know which row is the current line of the cursor, where is in the file, can use the key combination in the command mode, at this time, the VI will be on the last line of the display window Displays the corresponding information. This command can be used at any time.

In the last mode, we can enter the command NU (the abbreviation of words Number) to obtain the line number of the cursor current line and the line content.

Cursor mobile operation

In the full-screen text editor, the mobile operation of the cursor is undoubtedly the most frequently used operation. The user can only reach the desired location by using these commands that are skilled in using the mobile cursor.

The cursor movement in the VI can either in command mode, or in text input mode, but the method of operation is not the same.

In text input mode, you can move the cursor directly on the four direction keys on the keyboard.

In command mode, there are many ways to move cursors. Not only can you use four arrow keys to move the cursor, but also use H, J, K, L for the four arrow keys to move the cursor, which avoids the contradictions brought about by different keyboard definitions on different machines. And after using the skill, you can do all operations without leave the letter keyboard position, thereby increasing productivity. You can also move the cursor with , , , four keys or combinations. And the above three keys are equivalent to implementation. In addition, there are some commands of moving cursors. The following is the following ways to describe the following:

, * is called right-oriented key)

The right direction key is to move the cursor to the right. If you enter a number n in front of the right button, then the cursor moves N position to the right. For example, 5L indicates that the cursor moves 5 positions. It should be noted that the cursor movement cannot exceed the end of the current row. If a given N exceeds the number of characters at the current position of the cursor, if the right direction key is used, the cursor can only be moved to the end of the row; if , the cursor is moved to the appropriate position of the following line or several lines below.

H, ,? (left button)

Perform a left button, move the cursor to the left. Like the right button, you can also enter a number N to the left button, then the cursor moves n positions to the left. It should be noted that if the left direction keys, the cursor cannot be exceeded by the beginning of the line; if you use , the cursor is moved to the appropriate position above or a few rows.

J, , ˉ (down button)

Perform a down key cursor to move a position (ie, a line), but the column where the cursor is constant. When these commands add the digital N, the cursor is moved down.

In addition to the cursor, VI can be removed by the down button, and the key and " " key can be used to move the cursor down or N rows (excluding the Bank), but at this time, the cursor will be removed. The first character located in this line. E.g:

The 3J cursor is moved down to 3 lines, and the position of the column where the cursor is constant.

3 or 3 The cursor is moved to 3 lines, and the cursor is located in the line of the row.

K, , - (Up Key) Perform a position (ie, a line), but the column where the cursor is located unchanged. Also in front of these commands plus digital N, the cursor is moved on the N row.

If the cursor is visible, the cursor is located in the line of the line, and the command "-" can be used.

L (moving to the lead)

The command is to move the cursor to the beginning of the current row, so that the cursor moves to the first non-empty place (non-tab or non-air).

$ (Moved to the end)

This command moves the cursor to the row of the current row and stops on the last character. If you add a digital N before the command, the cursor is moved down and reaches the end of the row.

[Line number] g (move to the specified line)

This command moves the cursor to the line of the line specified by the specified line number. This movement is called absolute positioning.

[Example 8]

#include

Main ()

{INT K;

FOR (k = 0; k <3; k ) add ();

}

Add ()

{static int x = 0;

X ;

~

The cursor moved to the first line of line.

If the line number is omitted, the cursor moves to the final line of the file, that is, no matter how many screens are available, it is jumped to the last line.

Chapter 27 VI Order 2000 / June / 26

Move on the screen

The VI provides three commands on the cursor movement on the full screen and the file itself does not have scrolling. They are H, M and L commands, respectively.

H command

This command moves the cursor to the first line of the screen (ie, the upper left corner), which is the first line of the current screen, not the first line of the entire file. Use this command to quickly move the cursor to the top of the screen. If you add a digital N before the h command, the cursor is moved to the first line of the NP.

After entering the 4h command in command mode, the cursor is moved to the letter F of this line starting with FOR.

It is worth mentioning that the use of the command DH will delete all the contents of the first line of the screen displayed from the cursor.

M command

This command moves the cursor to the head of the middle line of the screen display file. That is, if the current screen is full, move to the middle line of the entire screen; if it is not full, move to the middle line of the lines of the text. With this command, you can quickly move the cursor from any position of the screen to the middle line of the screen display file. For example, in the case of the above screen display (regardless of where the cursor is on the screen), after the command mode is input, the cursor will move to the letter A of the ADD.

It is also worth mentioning that the use of the command DM will delete the entire content of the middle line from the cursor current to the screen display file.

L command

When the file display exceeds a screen, the command moves the cursor to the bottom of the bottom of the screen; when the file display is less than one-screen, the command moves the cursor to the last line of the file. It can be seen that this command can quickly accurately and accurately move the cursor to the last line of the bottom or file. If you add a digital N before the L command, the cursor moves to the first line of the Nth line from the bottom of the screen. For example, in the case of the above screen display (regardless of where the cursor is on the screen), after the command 3L is input, the cursor will move to the letter X of X this line.

It is also worth mentioning that the use of the command DL will delete all the contents from the cursor current to the bottom line.

Move cursor by word

First introduce the concept of "word" in VI. There are two meanings in "Word" in VI. One is a broad word, which can be anything between two spaces.

[Example 10] The 4th line in the file eXample.c: {INT K;

It only has 2 words, one is {Int, the other is K;

The other word in VI is a narrow word, in this sense, English words, punctuation symbols and non-alphabetic characters (such as!, @, @, $,%, ^, &, *, (,), -, , {,}, [,], ~, |, /, <,>, /, etc.) are all being used as a word. Therefore, the above line includes {, int, k, etc .; 4 words.

Using uppercase commands in VI is generally referring to the word as a broad sense, using lowercase commands is treated as a narrow.

After engage in the meaning of the word in the vi, we can introduce the command to move the cursor in word.

VI provides a total of three sets of commands on the word movement cursor, namely:

W and w command

Move the cursor to the header of the next word;

[Example 11] The screen is displayed as follows:

Printf ("Hello Mr.huang! / N");

Now use the W command, move the cursor to the next word (narrow "word" ("on:

Printf ("Hello Mr.huang! / N");

The following W command will be used to move the cursor to the next word (broad) word "m":

Printf ("Hello Mr.huang! / N");

E and E command

If the cursor starting position is in the word (ie, the non-word tail), the command will move the cursor to this character; if the cursor start position is at the tail, the command will move the cursor to the next word. suffix.

B and B

If the cursor is in the word (ie, the first), the command will move the cursor to this word; if the cursor is in the word first, the command will move the cursor to the first word.

[Example 12] The screen is displayed as follows:

Printf ("Hello Mr.huang! / N");

Now use the b command, since the cursor is in the middle of this word, the cursor moves to the first word "H":

Printf ("Hello Mr.huang! / N");

If you use a b command, you are as follows:

Printf ("Hello Mr.huang! / N");

Move the cursor in the sentence

In VI, a sentence is defined as a comma (,), the number (.), The question mark (?) And the exclamation mark (!), And it follows at least two (including two) spaces or a newline character Character sequence.

The VI provides two commands on the operation of the cursor, respectively:

Command

Move the cursor to the beginning of the previous sentence.

2.) Command

This command moves the cursor to the beginning of the next sentence.

Move cursor by segment

In VI, a segment is defined as a segment that starts and ends with a blank row. VI provides two commands on the movement cursor in segment, respectively:

1. {command

This command moves the cursor forward to the beginning of the previous paragraph;

2.} command

This command moves the cursor to the beginning of the next paragraph.

Screen scroll

The screen command is a screen and paging that moves cursors in units of screens. It should be noted that the screen command is not a cursor motion command, and cannot be used as a text qualifier to delete the command.

You can use the screen scroll command in command mode and text input mode. Schep command

There are two on the scroll command:

· Roll the screen forward (file head direction);

· Roll the screen backward (file tail direction).

You can add a number N before these two commands, then the screen is forward or backward. And this value is remembered, and the corresponding number of rows is also rolled by using the and command.

2. Package command

There are two paging commands:

· Roll up the screen in the file (ie, one page);

· Roll up the screen to the file (ie, one page).

You can also add a number n before these two commands, then move n pages forward or backward.

3. Status Command

The command displays the VI status information on the VI status line, including the file name being edited, whether it modifies, the current line number, the number of files, and the percentage of the entire file before the cursor.

4. Screen zero command

VI provides three commands related to screen zero. Their formats are:

· [Number] Z [Row number]

· [Number] z [line number].

· [Line Number] Z [Route] _

If the line number and the number of lines are omitted, the three commands are respectively re-display the current line where the cursor is located, the middle row, and the last line are redisplayed; if the line number is given, the line number corresponding to the line number As the current row, the first line, middle rows, and the last line are displayed; if the number of times is given, it specifies the number of rows displayed on the screen.

[Example 13]

8Z16 : Put the eighth line in the file as the first line of the screen, and a total of 16 lines.

15Z.: The middle line in the file is displayed as the middle line displayed by the screen, and the number of lines is displayed.

15Z 5_: Take the 15th line in the file as the last line displayed, the number of lines is 5 lines.

Text insertion operation

Any character of the user input in command mode is explained as a command as a command. If the user wants to use the character as a text content, first, the working mode of the VI should be switched from the command mode to the text input mode. The way to switch is to use the following command.

Insert (insert) command

VI provides two insert commands: I and I.

i command

Inserting the text begins before the cursor is located, and the key can be used to delete the incorrect input during the insert. At this time, the VI is inserted, and the screen is displayed at the bottom of the screen "--ensert -" (insert).

[Example 14] A file being edited as follows:

Welcome to vi world! Come ON!

~

~

The cursor is located in the first "!", You need to insert it in front:

This is an esample!

Use the i command and enter the corresponding text, the screen is displayed as follows:

Welcome to vi world this is an esample !! come on!

~

~

As can be seen from this example, the cursor is originally in the first "!", But since it starts to insert from the position where the cursor is located, this "!" Is squeezed to the newly inserted text.

I command

转载请注明原文地址:https://www.9cbs.com/read-130727.html

New Post(0)