Screen Text Editor VI

zhaozj2021-02-12  136

This chapter describes the most common text editor VI on Linux. Text Editor is the most commonly used tool in all computer systems. When users use a computer, they often need to build their own files, whether they are general text files, data files, or source program files, which are inseparable from editors. The Linux system provides a complete editor family series, such as ED, EX, VI, and Emacs, etc., which can be divided into two categories: line editor (ED, EX) and full screen editor (vi, emacs) . Each editor can only operate a line each time, it is very inconvenient to use. The full screen editor edits the entire screen, the user edited files directly displayed on the screen, the modified results can be seen immediately, overcome the non-intuitive way of operation of the line, easy to learn and use, powerful functions. VI is the first full-screen interactive editor of the Linux system. It has been favored by the majority of users since the birth. After decades, it is still a text editing tool that is mainly used by people, and it is strong, and powerful vitality. It is a powerful function. In this chapter, we will gradually introduce how to build, edit, display, and handle files using VI. (Note: Combination of uppercase letters [Shift] button corresponding lowercase letters) VI Introduction VI is the abbreviation of "Visual Interface", which is the same as the EDIT program on DOS on Linux. It can perform numerous text operations such as output, delete, lookup, replace, block operation, and users can customize them according to their needs, which is not available in other editor. VI is not a typographic program, which can be arranged such as Word or WPS to arrange other properties such as fonts, formats, paragraphs, which is just a text editing program. VI has no menu, only commands, and there are many commands. VI has three basic working modes: command line mode, text input mode, and end mode. At any time, if the user is in the mode, simply press the key, you can enter the command line mode; we entered the SHELL environment (prompt $) Enter the launch vi command, when entering the editor, it is also This mode is in this mode. In this mode, users can enter a variety of legitimate VI commands for managing their own documents. At this point, any characters entered from the keyboard are explained as the editing command. If the input character is a legal VI command, the VI completes the corresponding action after accepting the user command. However, it is important to note that the input command is not displayed on the screen. If the input character is not the legal command of the VI, the VI will ring the alarm. Text Input Mode Enter the insert command I, add command A, open command O, modify command C, replace command R or replacement command S can enter text input mode. In this mode, any character entered by the user is saved as a file content as the file content and displays it on the screen. In the text input, if you want to return to the command mode, press the key. The end mode terminal mode is also known as the EX escape mode. The functionality of the VI and EX editors is the same, and the two main differences are the user interface. In VI, the command is usually a single key, such as I, A, O, etc., in EX, the command is the end of the key to press the Enter key. VI has a dedicated "escape" command to access a lot of row EX commands. In command mode, the user presses the ":" key to enter the last line mode, at which time the VI will display a ":" as a prompt of the last line of the display window (usually the last line of the screen), Wait for the user to enter the command. Most file management commands are performed in this mode (such as writing the contents of the edit buffer to the file).

After the end command is executed, the VI is automatically returned to the command mode. For example: 1, $ S / A / A / G will replace all uppercase A to lowercase A from the first line of the file to the file. If you change your mind during the end mode, you can change your mind, or press all the commands to remove the input command, then press the back to command mode. The conversion between the three working modes of the VI editor is shown in Figure 11-1. If you want to convert from the command mode to the edit mode, you can type command a or i; if you need to return from the text mode, press the ESC key. Enter ":" in command mode to switch to the last line mode, then enter the command. Chapter 25 The entry of VI is logged in to the system after entering the user from 2000 / June / 13, and the system gives the prompt "$". Type VI after the prompt and you want to edit (or establish) file names, you can enter the VI. [Example 1] Type the command: $ vi eXample.c screen is shown below: ~~~~~~~~~~~~~ "example.c" [new file] If you only type VI, without file name, You can enter the VI. After that, type the file content at the cursor, when you exit the VI, you only need to enter the file name after exiting the command. After entering the VI, the first entry is the command mode, that is, waiting for the command input instead of text input. The alphabet entered at this time will be interpreted as a command. The cursor stops on the first line of the screen (with the representation), and the remaining rows have a "~" symbol, indicating that the behavior is blank. The last row also called the status line, showing the file name and its status currently being edited. If this example is [new file], eXample.c is a newly built file. If the example.c file has exist in the system, then after the above command is input, the contents of the file are displayed on the screen, and the cursor stops in the first line of the first line, and the file name of the file is displayed in the status line. Number and characters. [Example 2] Type command: $ VI EXAMPLE.C and type: #includemain () {INT K; for (k = 0; k <3; k ) add () add ();} add () {static int x = 0; X ; Printf ("x =% d / n", x);} ~~~~ "example.c" [new file] Note that we only show 15 lines in order to save space. In fact, the initial display line is related to the terminal used by the user, and the general CRT terminal can display 25 rows. In the window system, the number of lines is displayed is related to the window running VI. However, we can set the number of display lines. For example, on the CRT terminal that can display 25 rows, allows VI to display only 15 rows. The method of setting will be described later in this section. When a new file is created with VI, you may not give the file name in the command that enters the VI. When editing the file, you need to save the data, then specify the file name. When entering VI, users can specify a file name to be edited, but also have many additional operations. If it is desired to enter the VI, the cursor is on a certain line in the file, and the option n can be added after the VI, where n is the specified number of rows.

[Example 3] After the command: $ VI 5 example1.c, the screen is displayed as follows: #includemain () {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 cursor will be located on the 5th line in the file eXample1.c . If the cursor is in the final line after entering the VI, simply omit the numbers n after the appearance " " in the command. When entering the VI, in addition to the cursor starting line number, you can specify a mode string in the command. At this time, the cursor is in the file in the file, which matches the specified mode string. On line. [Example 4] Type command: $ VI / INT EXAMPLE1.C screen displays as follows: #includemain () {INT K; for (k = 0; k <3; k ) add ();} add () {static int int X = 0; x ; Printf ("x =% D / N", x);} ~~~~~ "Example.c" 12 Lines, 125 Characters cursor will be on page 3 in the file eXample1.c. Using VI can edit multiple files at the same time, as long as you write the file to be operated in the command to enter the VI, you can use wildcard. [Example 5] Type command: $ vi * .cat You can edit all the suffixs for CAT. Of course, you can also load files with built-in pattern in the shell, which will be better. Once you contain all the edited file names in the command line, you can remove it in VI. Exit VI When editing the file, you can use one of the following methods when you prepare to exit the VI to return to the shell. In command mode, connect to the uppercase letter z, if the current edited file has been modified, then the VI saves the file and returns to shell; if the current edited file is not modified, VI directly exits, Return to the shell. In the end mode, enter a command: WVI saves the current editing file, but does not quit, but continues to wait for the user to enter the command. When using the W command, you can give a new file name to the editing file. [Example 6]: w NewFile At this time, VI will save the contents of the current file to the specified newfile, and the original file remains unchanged. If newfile is an existing file, the VI gives the prompt information in the status line of the display window: File Exists (use! To override) At this time, if the user really wants to replace the current content of the file in Newfile Central Plains, Use the command: w! Newfile otherwise you can select another file name to save the current file. In the end mode, enter a command: Q System exits VI to return to the shell.

When you exit the VI with this command, the editing file is not saved, then the Live line of the VI is displayed as follows: No Write Since Last Change prompts that the file is not saved after the file is modified, then VI does not quit and continue to wait for the user command. If the user does not want to save the modified file, you can use the command: Q! VI to give up the changes directly to the shell. In the end mode, enter the command: WQVI will save the file first, then exit the VI to return to the shell. In the last line mode, enter a command: x The function of the command is the same as the zz command function in command mode.

Many of the commands in the line number VI in the VI are used to use the number of 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: Enter a command in the last mode :: Set Number What is needed, 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] #NCLUDE 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 (word Number Abbreviations to get the line number of the cursor current row and the line content. The cursor movement operation 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 works are described below: , "(all called right-pointed keys) 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. For example: 3J cursor is down 3 rows, 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-) 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 L command is moved to the beginning of the current line, so that the cursor moves to the first non-empty place (non-gauge or non-air). $ (Moved to the end) This command moves the cursor to the end of the current line 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 Specified Row) 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 command: 6G, 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 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. The twenty-seventh lesson vi command 2000 / June / 26 on the screen mobile VI provides three commands about the cursor moved on the full screen and the file itself does not have scrolling. They are H, M and L commands, respectively. 1. 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.

[Example 9] 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" [new file] After entering the 4h command in command mode, the cursor moves to this line starting with for. Letter f. 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. 2. m Commands 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. 3. L Command When the file display content exceeds a screen, the command moves the cursor to the bottom of the bottom of the screen; when the file display is not enough, the command moves the cursor to the last line of the file. first. 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. The word movement cursor first introduces the concept of "Word" in the VI. There are two meanings in "Word" in VI. One is a broad word, which can be anything between two spaces. [Example 10] Online 4 lines in the file eXample.c; {INT K; it only has 2 words, one is {INT, the other is k; VI, the other word is the word on the narrow sense, in this kind Under the meaning, English words, punctuation 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: 1. W and w commands to move the cursor to 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: "Hello Mr.huang! / N"); use the W command below will The cursor moves to the next word (generalized) word "m": Printf ("Hello Mr.huang! / N"); 2. E and E command If the cursor start position is in the word (ie non-character ), Then 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. 3. B and b If the cursor is in the word (Ie, not the first), then the command will move the cursor to this word; if the cursor is in the word first word, 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 b command, since the cursor is in the middle of this word, the cursor moves to this word "H": Printf ("Hello Mr. Huang! / N" If you use the b command, you look like this: Printf ("Hello Mr.huang! / N"); Move the cursor in VI, one sentence is defined as a comma (,), and the sentence (.), Question mark (?) And exclamation mark (!) End, and it follows at least two (including two) spaces or a newline character sequence. VI provides two commands on the operation of the cursor, respectively: 1 (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. Press Segment Move the cursor in the VI, one segment is defined as a blank line start and end Fragment .vi provides two commands on the segment moving cursor, respectively: 1. {Command This command moves the cursor forward to the beginning of a segment; 2.} Command This command moves the cursor backward to the next section The beginning. The screen scrolling screen command is used to move the cursor in the screen. It is important to note that the screen command is not the cursor movement command, and cannot be used as a text qualifier to delete the command. In command mode The screen scroll command can be used in the next and text input mode. 1. Run the scroll command There are two: · turn the screen forward (file head direction); · The screen is turned back to the back (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, after using and When the command scrolls, it also rolls Rows. 2. Page the page command There are two paging commands: · Roll up the screen to the file (ie one page); · Put the screen in the first direction of the file ( That is, one page).

You can also add a number n before these two commands, then move n pages forward or backward. 3. Status command Command Displays the VI status information on the VI status line, including the file name being edited, modified, the current line number, the number of files, the number of files, the percentage of the entire file before the cursor . 4. The screen zero command VI provides three commands related to the screen zero. Their formats are: · [Line Number] Z [Row] · [Line Number] Z [Route]. [Line Number] Z [Route] _ If omitted the number of line numbers and lines These three commands are redistributed by the current line where the cursor is located as the first line of the screen, the middle row, and the last line; if it gives the travel number, the line corresponding to the line number is the first to display the screen as the current line. Row, intermediate rows and the last line; if the number of travel 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 displayed by the screen, and a total of 16 lines is displayed. 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 Insert Operation In command mode, any character entered in command mode is explained as a command as a command. If the user wants to turn the input character as a text content, first should switch the Work mode of the VI from the command mode to the text. Input mode. The way to switch is to use the following command. The Insert Command VI provides two insert commands: I and I. 1. The I command is inserted into the text before starting the location of the cursor, and the key can be removed by the key during the insertion. At this time, the VI is inserted, and the screen is displayed at the bottom of the screen "--ensert -" (insert). [Example 14] There is a file that is editing, as shown below: Welcome to vi world! Come on! ~~ The cursor is in the first "!", You need to insert it in front: this is an example! Use the i command, and After entering the corresponding text, the screen is displayed as follows. Welcome To Vi World this is an esample !! come ON! ~~ From this case, the cursor is originally in the first "!", But because it is located from the cursor Before starting, this "!" Is squeezed to the newly inserted text. 2. I Command This command is the leading position to the current line, and then insert the text before it.

The VI command moves VI on the screen to provide three commands about the cursor moved on the full screen and the file itself does not have a scrolling. They are H, M and L commands, respectively. 1. 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. [Example 9] 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" [new file] After entering the 4h command in command mode, the cursor moves to this line starting with for. Letter f. 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. 2. m Commands 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. 3. L Command When the file display content exceeds a screen, the command moves the cursor to the bottom of the bottom of the screen; when the file display is not enough, the command moves the cursor to the last line of the file. first. 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. The word movement cursor first introduces the concept of "Word" in the VI. There are two meanings in "Word" in VI. One is a broad word, which can be anything between two spaces. [Example 10] Online 4 lines in the file eXample.c; {INT K; it only has 2 words, one is {INT, the other is k; VI, the other word is the word on the narrow sense, in this kind Under the meaning, English words, punctuation 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: 1. W and w commands to move the cursor to 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: "Hello Mr.huang! / N"); use the W command below will The cursor moves to the next word (generalized) word "m": Printf ("Hello Mr.huang! / N"); 2. E and E command If the cursor start position is in the word (ie non-character ), Then 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. 3. B and b If the cursor is in the word (Ie, not the first), then the command will move the cursor to this word; if the cursor is in the word first word, 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 b command, since the cursor is in the middle of this word, the cursor moves to this word "H": Printf ("Hello Mr. Huang! / N" If you use the b command, you look like this: Printf ("Hello Mr.huang! / N"); Move the cursor in VI, one sentence is defined as a comma (,), and the sentence (.), Question mark (?) And exclamation mark (!) End, and it follows at least two (including two) spaces or a newline character sequence. VI provides two commands on the operation of the cursor, respectively: 1 (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. Press Segment Move the cursor in the VI, one segment is defined as a blank line start and end Fragment .vi provides two commands on the segment moving cursor, respectively: 1. {Command This command moves the cursor forward to the beginning of a segment; 2.} Command This command moves the cursor backward to the next section The beginning. The screen scrolling screen command is used to move the cursor in the screen. It is important to note that the screen command is not the cursor movement command, and cannot be used as a text qualifier to delete the command. In command mode The screen scroll command can be used in the next and text input mode. 1. Run the scroll command There are two: · turn the screen forward (file head direction); · The screen is turned back to the back (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, after using and When the command scrolls, it also rolls Rows. 2. Page the page command There are two paging commands: · Roll up the screen to the file (ie one page); · Put the screen in the first direction of the file ( That is, one page).

You can also add a number n before these two commands, then move n pages forward or backward. 3. Status command Command Displays the VI status information on the VI status line, including the file name being edited, modified, the current line number, the number of files, the number of files, the percentage of the entire file before the cursor . 4. The screen zero command VI provides three commands related to the screen zero. Their formats are: · [Line Number] Z [Row] · [Line Number] Z [Route]. [Line Number] Z [Route] _ If omitted the number of line numbers and lines These three commands are redistributed by the current line where the cursor is located as the first line of the screen, the middle row, and the last line; if it gives the travel number, the line corresponding to the line number is the first to display the screen as the current line. Row, intermediate rows and the last line; if the number of travel 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 displayed by the screen, and a total of 16 lines is displayed. 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 Insert Operation In command mode, any character entered in command mode is explained as a command as a command. If the user wants to turn the input character as a text content, first should switch the Work mode of the VI from the command mode to the text. Input mode. The way to switch is to use the following command. The Insert Command VI provides two insert commands: I and I. 1. The I command is inserted into the text before starting the location of the cursor, and the key can be removed by the key during the insertion. At this time, the VI is inserted, and the screen is displayed at the bottom of the screen "--ensert -" (insert). [Example 14] There is a file that is editing, as shown below: Welcome to vi world! Come on! ~~ The cursor is in the first "!", You need to insert it in front: this is an example! Use the i command, and After entering the corresponding text, the screen is displayed as follows. Welcome To Vi World this is an esample !! come ON! ~~ From this case, the cursor is originally in the first "!", But because it is located from the cursor Before starting, this "!" Is squeezed to the newly inserted text. 2. I Command This command is the leading position to the current line, and then insert the text before it. } The 25th lesson VI command 2000 / July / 10 Addition (APPEND) command VI provides two additional insert commands: A and A. 1. A Command This command is used to add new text after the cursor is currently located. After the newly input text is placed behind the cursor, the original text after the cursor will move backwards. The cursor can be in any position in one line. [Example 15] Take the original case as an example 14, using a command, and enter the corresponding text, the screen is displayed as follows: Welcome to vi world! This is an example! Come on! ~~ The text after the cursor in this example "come on "" The newly entered text is squeezed behind. 2. a Command This command is different from the A command, the A command will move the cursor to the line of the line, starting to insert a new text. When the A command is input, the cursor is automatically moved to the row of the row. The A and A commands are the only way to insert text into the end of the line.

Open (open) command is that the insert command is also, or the append command is good, and the inserted content begins with a location in the current row. If we want to insert some new rows before or after a row, you should use the Open command. VI provides two open commands: O and O. 1. O Command This command will open a row under the row of the cursor and place the cursor in the line of the row, waiting to enter text. Note that when you use to delete characters, you can only delete characters from the starting position from the insert mode, which does not work for previous characters. And you can also enter some control characters in a text input mode, for example, Ctrl L is inserted into a paging, and is displayed as ^ L. [Example 16] As an example, the original case of Example 14 is exemplified, but this time it is necessary to enter text in the current row. Use the O command, and enter the corresponding text, the screen is displayed as follows: Welcome to vi world! Come ON! This is an example! ~~ The newly entered text appears in the next line of the original text. 2. O commands and O commands, the O command is inserted in the upper side of the row in the cursor, and places the cursor in the line of the line, waiting for input text. [Example 17] That is the same as the original situation of Example 14, you must enter text on the top of the current row. After using the O command and enter the text, the screen is displayed as follows: this is an example! Welcome to vi world! Come on! ~~ text inserted to the current row. 11.3.4 Text Modifications You can modify the text in command mode, including deletion, replication, replacement, and replacement of text content. Text Remove When editing text, you often need to delete some unwanted texts, we can use the key to delete the error or unwanted text, but at this time, if you delete the line, you want to delete it. The content of the line is impossible. In command mode, VI provides a lot of delete commands. Most of these orders are at the beginning of D. Commonly used: 1. Delete a single character x: Delete the characters at the cursor. If you add a number N before X, remove the n characters from the position where the cursor is located. X: Delete the character in front of the cursor. If you add a number N before X, remove the n characters from the front of the cursor to the left. Obviously these two commands are shortcuts that delete a small amount of characters. 2. Delete multiple characters DD: Delete the entire line where the cursor is located. A number N can be added before the DD indicates the content of the current line and the subsequent line thereafter. D or D $: Two command functionality is the content that starts from the cursor to the end to the end. D0: Delete the content starting from the previous character from the cursor to the lead. DW: Delete a word. If the cursor is in the middle of a word, then delete the word tail from the position where the cursor is located. Like the DD command, you can add a number N before DW, indicating that the N-specified words can be deleted. If the user accidentally deletes the operation, it is not tight, and the VI provides a command to recover mistakes, and the recovered content can be moved, placed anywhere in the text. The recovery command is 2 NP, where n is the register number. This is because there are nine registers for maintaining the delete operation, respectively, with numbers 1, 2 ,?, 9, respectively, save the content deleted in the previous DD command. These registers form a queue, such as the content that is most recently used by the DD command is placed in the register 1; when the text content is removed using the DD command next time, the VI will transfer the contents of the register 1 into the register 2, and the register 1 It will be the content of the most recent DD command deletion.

In this class, the VI can save the content that has recently been deleted with the DD command, while the previous use of the DD command deleted is abandoned. [Example 18] Assume that the current edited file is xu.c / * this is a example * / # include void main () {INT I, J; Printf ("please input a number: / n"); Scanf ("% D", & i); j = i 100; Printf ("/ nj =% d / n", j); return;} We do this: 1. Move the cursor to file first Row, press the DD command, the content of the first line of the file is deleted, and the deleted content is saved in the register 1; 2. Press 5J to move the cursor to the first printf statement line; 3. Press the DD command The row is deleted, and the register 1 will be saved in the register 1: Printf ("please input a number: / n"); and the register 1 original content: / * this is a example * / is saved to Register 2; in the last line mode, you can also delete the contents of the file, but it can only delete the entire line, once a specified range (start line number, termination line number) can be removed all over a time . It should be noted that when this method is deleted, the VI does not place the deleted content into the register, so when the error is removed, the 2 NP command cannot be recovered, and only a limited recovery can be performed with a U command. Finally, how to delete the text in the text input mode. The user can use the key button, and this time the cursor will return the position where the insert start is inserted, and the VI is still in the text input mode. Cancel Previous Command (Undo) Cancel Previous Command (Undo), also known as the restoration command, is a very useful command, it can cancel the previous misoperation or inappropriate operation of the influence on the file, make it reply to this Mismused or inappropriate operations are performed before. There are two forms in cancellation, and in command mode, type characters U and U. Their functions are canceled the command that just entered and returns to the original situation. Small write u and uppercase U have different details, the difference between the two is that the function of the uppercase U command is to restore the case before the misoperation command, that is, if the U command is used after the command is inserted, it deletes the content just inserted; If you use a U command after deleting the command, it is equivalent to inserting the content just deleted again at the cursor. Here, all modified texts are treated as inserted commands. That is, the U command can only cancel the previous step, if the previous step is to undo, when pressing the U key, not to undo the next step, but revoke the operation of the current U command, That is, it is restored to the status before the first time using the u command, and the result is nothing. The function of lowercase U commands is to restore the current row into the status before editing, regardless of how many times the line is edited.

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

New Post(0)