Suggestion: This article is intended for users who are new to the Unix VI editor. The detailed command table paid later can also be used as a reference for users who are already familiar with VI, therefore, you 'd better download this article or print it out and learn from it. <Br/> 1. UNIX editor overview </P> <p> the editor is an important tool for using computers. It is an essential component in various operating systems. UNIX and similar IX </P> <p> in the operating system series, a series of ex editors, including ex, edit, Ed, and </P> <p> VI. ex, edit, and Ed are all row editors, which are rarely used now, the reason UNIX provides them is that it meets the needs of various users </P> <p>. </P> <p> fortunately, Unix provides a full-screen VI Editor, which makes our work much easier. Many dos users complain that the VI editor is not as easy as </P> <p> the edit editor in DOS is so easy to use, because VI takes into account the needs of various users, some general editing keys are not used (their definitions are different on different </P> <p> terminals, and they are not even used on some terminals ). The status switch method is used, but this </P> <p> is just a habit. Once you use VI skillfully, you will think it is actually very useful. </P> <p> although VI adopts the state switching method, the hardware and operating system of the computer are diverse, some computers do not have a specific number of functions on their keyboards </P> <p> power keys! Isn't some functions unavailable? This problem is also the same in Unix systems. Almost all major computer manufacturers have their own </P> <p> Unix systems, and the VI operation methods will also be somewhat different. Here we use a PC keyboard to describe VI operations, but in the specific </P> <p> environment, we also need to refer to the relevant information, this is worth noting. </P> <p> introduction to VI </P> <p> (1), enter VI </P> <p> type VI under the system prompt characters (such as $, #) <File Name>, vi can automatically help you load the file to be edited or open a new </P> <p> file (if the file does not exist or the file name is missing ). After entering VI, A Tilde sign will appear on the left side of the screen. Any column with this symbol at the beginning will be replaced by </P> <p> This column is currently empty. </P> <p> (2) Two modes </P> <p> as described above, there are two modes in VI: Command mode and input mode. In command mode, keys entered are processed as commands. For example, if you enter </P> <p> A, VI inserts a character at the current position. In the input mode, VI treats the Input key as the inserted character. Command </P> <p> to switch to the input mode, you only need to enter the corresponding input command (for example, a, a), and switch from the input mode to the command mode, you need to enter the ESC key in </P> <p> input mode. If you do not know the current mode, you can press [ESC] several times. if the system beeps, the table </P> <p> indicates that it is in the command mode. </P> <p> pay: a command that enters the input mode in command mode: </P> <p> Add (append) </P> <p>: add data from the end of the cursor position, and move the data after the cursor along with the new data. </P> <p> A: add data starting from the bottom of the column where the cursor is located. </P> <p> insert </P> <p> I: insert data from the front of the cursor, and move the data after the cursor to the backend as the new data is added. </P> <p> I: insert data starting from the first non-blank character in the column where the cursor is located. </P> <p> Start (open) </P> <p> O: adds a column under the column where the cursor is located and enters the input mode. </P> <p> O: adds a new column to the column where the cursor is located and enters the input mode. </P> <p> (3) Exit VI </P> <p> in command mode, type: Q,: Q !,: WQ or: X (Note: No.), the VI will be exited. Where: WQ and: X are stored and exited, while Q is directly exited. </P> <p> If the file has new changes, VI will prompt you to save the file: the Q command also becomes invalid. In this case, you can use the: W command to save the file and then use: q </P> <p> to exit, or use the: WQ or: X command to exit, if you do not want to save the changed file, you need to use Q! Command to exit VI without saving the file </P> <p>. </P> <p> (4) Basic editing </P> <p> works with function keys on the general keyboard, such as direction keys, [insert], and [delete, now you can use VI to edit the file </P> <p>. Of course, VI also provides many other functions to facilitate text processing. </P> <p> what is editing? It is generally regarded as the addition, modification and deletion of text, and even the moving and copying of text blocks. This section describes how to delete and modify VI </P> <p>. (Note: In the original concept of VI, input and editing are two things. Editing is performed in command mode </P> <p>. You can use the command to move the cursor to locate the location to be edited before editing the command .) </P> <p> command for deleting and modifying a file: </P> <p> X: Delete the character where the cursor is located. </P> <p> DD: Delete the column where the cursor is located. </P> <p> r: Modify the character of the cursor, followed by the character to be corrected. </P> <p> r: Enter the replacement status. The new text overwrites the original text until you press [ESC] to return to the command mode. </P> <p> S: deletes the character of the cursor and enters the input mode. </P> <p> S: deletes the column where the cursor is located and enters the input mode. </P> <p> actually, there is no such trouble on PC! Both input and edit operations can be completed in input mode. For example, to delete a character, simply press <br/> [delete. However, you can directly use [insert] to switch between the insert status and the replace status, making it impossible to compile commands in any command mode. <br/>. However, as mentioned above, these commands can be used on almost every terminal, rather than just on a PC. <Br/> in command mode, the basic commands for moving the cursor are H, J, K, and L. I think you should be able to guess that you only need to directly use the PC direction <br/> key, and both in command mode and input mode. Not easy. <Br/> of course, the PC keyboard also has shortcomings. There is a good command u to restore the deleted text, while the U command can restore all changes in the column of the cursor <br/>. This is the same as the [undo] button function on some computers. <Br/> 3. Appendix: VI detailed instruction table <br/> (1). Basic editing instruction: <br/> Add (append) </P> <p>: add data from the end of the cursor position, and move the data after the cursor along with the new data. </P> <p> A: add data starting from the bottom of the column where the cursor is located. </P> <p> insert </P> <p> I: insert data from the front of the cursor, and move the data after the cursor to the backend as the new data is added. </P> <p> I: insert data starting from the first non-blank character in the column where the cursor is located. </P> <p> Start (open) </P> <p> O: adds a column under the column where the cursor is located and enters the input mode. </P> <p> O: adds a new column to the column where the cursor is located and enters the input mode. </P> <p> X: Delete the character where the cursor is located. </P> <p> DD: Delete the column where the cursor is located. </P> <p> r: Modify the character of the cursor, followed by the character to be corrected. </P> <p> r: Enter the replacement status. The new text overwrites the original text until you press [ESC] to return to the command mode. </P> <p> S: deletes the character of the cursor and enters the input mode. </P> <p> S: deletes the column where the cursor is located and enters the input mode. </P> <p> (2) cursor movement command: <br/> because many edits are positioned by the cursor, VI provides many ways to move the cursor, here are the <br/> several simple tables (these are commands in the command mode, of course ): <br/> certificate ----- certificate ------------- certificate ----- certificate <br/> │ instruction │ description │ function key │ <br/> certificate ----- certificate ------------- certificate ----- certificate <br/> │ 0 │ move to the front of the column where the cursor is located. │ [home] │ <br/> ← ----- {----------- ← ----- ← <br/> │ $ │ move to the back of the column where the cursor is located. │ [end] │ <br/> hour ----- hour ------------- hour ----- hour <br/> │ [CTRL] [d] │ next half page │ <br/> hour ----- hour --------------- hour ----- direction <br/> │ [CTRL] [f] │ to the next page │ [Pagedown] │ <Br/> certificate ----- certificate ------------- certificate ----- certificate <br/> │ [CTRL] [u] │ up half page │ <br/> certificate ----- certificate ------------- certificate ----- Certificate <br/> │ [CTRL] │ to the previous page │ [Pageup] │ <br/> certificate ----- certificate ------------- certificate ----- certificate <br/> certificate -- certificate ----------------- certificate <br/> │ instruction │ description │ <br/> export -- export ----------------- export <br/> │ H │ move to the first column of the window │ <br/> export -- export ----------------- export <br/> │ M │ move to the middle column of the window │ <br/> export -- export ----------------- export <br/> │ l │ move to the last column of the window │ <br/> export -- export ----------------- actions <br/> │ B │ move to the first letter of the next word │ <Br/> tips -- tips --------------- tips <br/> │ W │ move to the first letter of the previous word │ <br/> tips -- tips --------------- tips <br/> │ E │ move to the last letter of the next word │ <br/> Jun -- Jun --------------- Jun <br/> │ ^ │ move the cursor to the first non-blank character │ <br /> certificate -- certificate ----------------- certificate <br/> certificate -- certificate ------------------- certificate <br/> │ instruction │ <br/> certificate -- certificate ------------------- certificate <br/> │ n -│ move the minus sign to the first non-blank character in the previous column │ <br/> │ Add a number before the minus sign to specify to move to the n columns │ <br/> else -- else ----------------- else <br /> │ N + │ + + move the plus sign to the first non-blank character in the next column │ <br/> │ + A number before │ Specify to move to the following n columns │ <br/> Jun -- Jun ----------------- Jun <br/> │ ng │ directly move to column N │ using numbers N and uppercase G <br/> Jun -- certificate ------------------- hour <br/> hour ---- hour --------------- hour <br/> │ instruction │ description │ <br/> hour ---- hour --------------- hour <br/> │ move FX to the right to x character │ <br/> │ FX │ move to the left to X character │ <br/> Jun ---- Jun ------------- Jun <br/> │ TX │ move to the right to x character │ <br /> │ TX │ move to the left to the front of X characters │ <br/> bytes ---- bytes ------------- bytes <br/> │; │ use with F & T, repeat once │ <br/> │, │ use with F & T, and repeat once in the opposite direction │ <br/> Accept ---- accept- -------------- Bytes <br/> │/string │ move to the right to a place with a string │ <br/> │? String │ move to the left to a place with a string │ <br/> bytes ---- bytes ------------- hour <br/> │ n │ /&? Use, repeat │ <br/> │ n │ /&? Use, repeat the │ <br/> └ ---- ┴ --------------- ┘ <br/> ┌ ---- ┬ ----------------- ┬ ---------- ┐ <br/> │ instruction │ description │ remarks │ <br/> ├ ---- else ------------------- else ---------- else <br/> │ N (│ move the left parenthesis to the beginning of the sentence │ the sentence is │ <br/> │ Add a number before the │ you can specify to move n forward sentence │! .? Three symbols to define │ <br/> │ N) │ move the right brackets to the beginning of the next sentence │ <br/> │ Add a number to the front to specify to move n sentences │ <br/> else ---- else ------------------- else ---------- ↑ <br/> │ n {│ move the left arc to the beginning of the paragraph │ the section is │ <br/> │ Add a number to the front of the section to move n paragraphs forward │ between paragraphs define the blank column │ <br/> │ n} │ move the right arc to the beginning of the next section │ <br/> │ Add a number to the front to specify to move n section │ <br/> upper ---- upper ------------------- lower ---------- lower <br/> (3) and more editing commands <br/> these editing commands are very flexible and basically consist of commands and scopes. For example, DW is composed of the DELETE command D and the range W <br/>, meaning to delete a word D (elete) W (ORD ). <Br/> command list: <br/> D Delete <br/> Y copy (Yank) <br/> P put (Put) <br/> C change <br/> the range can be: <br/> E cursor position to the last letter of the word <br/> W cursor position to the first letter of the next word <br/> B cursor position to the first letter of the previous word <br/> $ the cursor location to the last letter of the column <br/> 0 cursor location to the first letter of the column <br/> br/>) cursor location to the first letter of the next sentence <br/> (cursor location to the first letter of the sentence <br/>} cursor location to the bottom of the paragraph A letter <br/> {the cursor is located at the first letter of the paragraph <br/> to be honest, combining these commands to edit files is a little artistic. In any case, they provide more text editing capabilities. <Br/> it is worth noting that deletion and replication will put the content within the specified range in the temporary storage area, and then you can use the command P to paste it to other places, this <br/> method is used by VI to process the copy and movement of segments. <Br/> some VI versions, such as Elvis used in Linux, can greatly simplify this instruction. If you look at these editing commands a little bit <br/>, you will find that the problem is actually a bit complicated by the fixed range method. In fact, there are only four commands. Command V is very easy to use. As long as you press the V Key, <br/> the position where the cursor is located will be reversed, and then you can move the cursor to set the range, then you can directly edit the command. <Br/> for the entire column operation, VI also provides more convenient editing instructions. As mentioned above, the command dd used to delete the entire text column is one of them. <br/> CC can modify the entire text column, while YY can copy the entire text column; command D deletes all text from the cursor until the end of the column. <Br/> (4) file operation commands <br/> file operation commands start with ":", which is a little different from editing commands. <Br/>: Q end editing (quit) <br/>: Q! You must discard edited files without archiving them. <Br/>: W: Save the file (write) and add the file name to be archived. <Br/>: The WQ file is archived and then left. <Br/> ZZ functions are the same as: WQ. <Br/> same as: WQ