After a long period of learning about Vi, Linux Vi can improve the machine's easy-to-use performance. Next we will talk about Linux Vi editing. Red Hat announced that it would integrate the original Red Hat Linux development plan with the Fedora Core Linux plan into a new Fedora Project. The Fedora Project will be sponsored by Red Hat.
Linux Vi Entry
After the user logs on to the system, the system prompts "$ ". Enter the name of the Linux Vi file and the file you want to edit or create.
Type the command:
$ Vi example. c "example. c" [New File]
If you only Type Vi without a file name, you can also enter Linux Vi. Then, enter the file content at the cursor. When you exit Linux Vi, you only need to enter the file name after exiting the command.
After entering Linux Vi, you first enter the command mode, that is, waiting for command input instead of text input. The entered letters are interpreted as commands. The cursor is displayed at the first line of the screen. Symbol, indicating that the behavior is empty. The last line is also called the status line, showing the name of the currently edited file and its status. In this example, [New File] indicates that example. c is a New File. If example. the c file already exists in the system. After you enter the preceding command, the content of the file is displayed on the screen and the cursor is placed at the first line, the file name, number of lines, and number of characters are displayed in the status line.
Type the following command:
$ Vi example. c and then type:
# Include
Main)
{Int k;
For k = 0; k <3; k ++) add );}
Add)
{Static int x = 0;
X ++;
Printf "x = % d \ n", x );
"Example. c" [New File]
Note: To save space, only 15 lines are displayed on the screen. In fact, the initial number of displayed rows is related to the terminal used by the user. Generally, 25 rows can be displayed on the CRT terminal. In the window system, the number of lines displayed is related to the window running Linux Vi. However, we can set the number of displayed rows. For example, on a CRT terminal that can display 25 rows, let Vi display only 15 rows. The setting method is described later in this section.
When a new file is created using Vi, the file name is not provided in the Linux Vi command. When the file needs to be saved after editing, the User specifies the file name. When you enter Linux Vi, you can not only specify a file name to be edited, but also have many additional operations. If you want to move the cursor to a specific row in the file after entering Linux Vi, you can add the option + n after Vi, where n is the specified number of rows.
Type the following command:
After $ vi + 5 example1.c, the screen is displayed 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 will be placed on line 5th in file example1.c.
If you want to move the cursor to the last line of the file after entering Linux Vi, you only need to omit the number n after the additional item "+" in the command. In addition to specifying the starting line number of the cursor, you can also specify a mode string in the command. After Entering Linux Vi, the cursor is on the first line in the file that matches the specified pattern string.
Type the following command:
The $ vi +/int example1.c screen is shown 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 will be placed on line 3rd in file example1.c.
You can use Linux Vi to edit multiple files at the same time, as long as you write the file to be operated in the command to enter Vi, you can also use wildcards.
Type the command: $ vi *. cat
You can edit all files suffixed with cat. Of course, you can also use the built-in pattern matching in shell to load files, which is more skillful. Once you include all the files to be edited in the command line, you can easily move them in Linux Vi.
- Linux vi editor concepts
- Describes how to use the basic commands of the linux vi editor.
- Linux vi command replacement instructions
- Practical Tips: linux vi command shortcut key set
- Linux vi command details and usage tips