Linux usage about VI

xiaoxiao2021-03-06  21

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.

[Example 7]

#include

Main ()

{INT K;

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

}

Add ()

{static int x = 0;

X ;

Printf ("x =% d / n", x);

}

~

~

~

~

~

"EXample.c" [modified] LINES 4 of 10 - 40% - COL 11

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:

, ® (known as rightmost ")

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, , ¬ (to the 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 Key) Perform a down key cursor to move a position (ie, one 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 (i.e., a line), but the column where the cursor is located. 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 ;

Printf ("x =% d / n", x);

}

~

~

~

~

~

"EXample.c" 12 lines, 125 Characters

Type the command: 6G, the screen is as follows:

#include

Main ()

{INT K;

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

}

Add ()

{static int x = 0;

X ;

Printf ("x =% d / n", x);

}

~

~

~

~

~

"EXample.c" 12 lines, 125 Characters

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.

(Transferred from

http://www.popsoft.com.cn)

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

New Post(0)