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
[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
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
H,
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
J,
In addition to the cursor, VI can be removed by the down button, and the
The 3J cursor is moved down to 3 lines, and the position of the column where the cursor is constant.
3 or 3
K,
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)