There are two modes after entering the VI 1. Edit mode 2. The command mode is default the command mode, so don't make the DD warning, if you want to enter text, please start entering the text ! After entering the end, press the ESC button back to command mode input Q is to exit the input WQ is the deployment of the input Q! Abandon the deposit for ambit. VI is already a standard text editor in the UNIX system, each network management must be familiar It, because you will often encounter it when maintaining your system. VI is that the first impression is always bad, I feel that it is difficult. In fact, after using the office software, I will use it back. These unseen monsters, it is inevitable that it is normal. But don't forget that you will be a person in the school's important network management, your role is no longer a pure user, but a face Managers and issues of complex networks, you must be able to manipulate your system, set your system, adjust your system, and this process, you have to face vi. Don't take Word's usage habits Pick-up vi, their role is different, the style is different, once you can go up, maybe you will like it. VI is the standard left and right hand of the network management person. So, open your heart, accept more harvest than rebound. Two Open the file, close the file VI file Name Turn on the file: Method Q Leave the (command) WQ store and leave (command column) Q! Give up the deposit, force the departure (command column) zz storage and then leave (not in the command column Use: e Dialing in VI. On the VI. Three. VI's operating mode: VI has two main mode of operation, the ESC key is a one-way switch button (input mode back to the editing command mode by this article) Edit Command Mode: To do some of the actions of specific purposes. Such as insert, additional, replacement, modification, deletion, mobile cursor, search, etc. If the operator is waiting, you need to go down to the command column, want to switch to the command column, you need to press: This article input mode: In this mode, any character is considered input data. After entering the VI, you will enter the editing command mode, each character you entered, is pre-admitted to a directive. Effective instruction It will be accepted, if it is an invalid instruction, it will generate a beep beep sound to show a warning. If you want to do the input action, you must switch to this article input mode, switch, as long as you click on a special meaning character key, as follows As shown: Press the I or i inserted Status Press the A or A Additional Status Press the R Senching Status R to replace a consecutive character to replace the S or S to delete a character; remove the cursor location Press CW, C2B, C, C0 to modify the state O or o Add a blank column, you don't have to use it all, as long as you will be i, a, o this three modes are good, because most times, You can only use these three. OK, now you can try some information to see. Then, press the ESC to switch back to the edit command mode. IV. Move the cursor: VI For applicable to a variety of different Terminal mode, therefore manipulate the cursor in a word key. KJHL up and down left and right ENTER change WB forward; go back to a word 0 $ to the beginning of the column; to the tail end - to the next column; Keep in mind: In VI, most of the commands can add numbers in front of it, the number indicates the number of times of the command. For example: 8L means moving 8 characters to the right, 3W indicates forward three Word, 2b represents 2 Word Note: Word definition, continuous English digital yuan form a word, and other special symbols are a word Word (unless continuous special characters), for example: - Classify contains 2 Word, one is -;
One is Classify and -X, there are 3 words. In special terminal mode, the arrow keys can be used. Such as Linux or VT100. In fact, you can still use the habit of using the direction key. But Probably only Local can only use PGUP, PGDN, End, Home and other keys! However, if you use the terminal mode does not support the arrow keys, the button in the above table is quite important. V. Volume Page: ^ f GoWard ^ b Top the next page (DOWN) ^ U Top Screen (UP) 6. Extremely: You can specify a list of positions Before the beating, check out how much the number of columns you are now. ^ G can display the current location, such as: "ls.txt" Line 53 of 264 --20% - COL 16-23 above, currently 53 columns, all of the total of 264 columns, accounting for 20 percent of the file, the current cursor, actually on the 23rd line, but only counted in the 16th line, because there is a Tab button in the middle. 80g or 80GG jumps to the first 80 column G jumps to the file tail GG and jumps to the file header. Delete: (but does not enter this article input mode) X Delete a character DD Delete a row R to replace a character or more of the current location of the cursor. And DW , DB, DE, D0, D $, etc., but you don't have to use it all. These three are enough. Remember a tips: Vi's commands, but you don't have to get started And these are enough. Eight. Undo (Reply Action): If you repent, you can use the UNDO function: u Cancel the change in the previous action U Cancel all the changes in the column where the cursor is: e! Cancel all changes, respond to untiible before nine. Key words search / replacement: / Key words to search keywords? Key words Top search keyword N Re-search command (no matter the down or up) N and N opposite direction CW string replaces the original keyword n. Continue to replace the action% S / target / replacement / g of the string to completely change the target string to replace strings. Selection, copy and move : Y or YY Select the cursor where the column 5Y or 5YY selects the spot 5 column (5 is just an example, you can use other numbers) P After selecting the content, copy to the cursor, P Take the content, copy to the cursor Previous CW, X, DD, etc. Delete commands will be put out in content In buffer, the effect of mobility can be made. 11. Temporarily jump out of the VI: In the editing process, you may want to perform other commands, the method is as follows::! Command execution This order: SH Temporarily jump out of VI , Want to return to VI Press ^ D or EXIT
VI's Working Mode Editing Mode Insert Mode Command Mode SHELL Switch Option Set VIM and GVIM Advanced Features 1.6.1 VI Operation Mode VI First Enter Edit Mode after initial startup, then users can use some predefined buttons to move cursor , Delete text, copy, or paste text, etc. These buttons are ordinary characters, such as L, moving the cursor to the right, equivalent to the right arrow keys, K is moving down the cursor, equivalent to the down arrow key. In editing mode, users can also use some special buttons to select text, then delete, or copying. When the user typed I, A, O and other commands in edit mode, you can enter the insert mode; type: You can enter the naming mode. In the insert mode, the user then enters, any character other than ESC will be seen as a character inserted into the edit buffer. After pressing Esc, switch from the insert mode to the edit mode. In command mode, VI will move the cursor to the bottom of the screen and display one at the position of the first character: (colon). At this time, the user can type some commands. These commands can be used to save files, read file content, execute the shell command, set the VI parameters, find strings or replace strings in a regular expression. 1.6.2 Editing Mode 1. Move the cursor to modify the content, first move the cursor to the specified location. The easiest way to move the cursor is to press the upper, lower, left and right arrow keys on the keyboard. In addition to this most original approach, the user can also utilize the numerous character combinations provided by the VI, move the cursor in the body, quickly reach the specified row or column, and implement positioning. For example: K, J, H, L function is equivalent to the upper, lower, left, right arrow keys Ctrl b move upward (equivalent to the PageUp key) Ctrl F moves down in the file ( Equivalent to the PAGEDOWN key) h Move the cursor to the top of the screen to move the cursor to the nth line 2H of the screen to move the cursor to the second row m to move the cursor to the middle of the screen to the screen. The cursor moves to the bottom of the screen to move the cursor to the countdown nth line 3L of the screen to move the cursor to the countdown line W in the screen W, right-handed the cursor inside the specified line, to the beginning of the next word E. Right shifting the beam, to the end of the word B. The left shot in the specified line, the beginning of the previous word 0 digits 0, the left shidder, to the beginning of the Bank, right moving the cursor, to the end of the Bank, "mobile cursor, To the first non-empty character cursor movement command: instruction description function key 0 Move the front [home] $ moving to the cursor where the cursor is listed, the last side of the column [end] [Ctrl] [D] The second half page [PageDown] [ctrl] [f] Next [Ctrl] to the upper page [Ctrl] to the upper page [PageUp] h Move to the first column M moved to the window M move to the intermediate column L moving to the window The last column B moving to the next word of the next word W moves to the first letter of the previous word e moves to the last word of the next word ^ Move the first non-blank in the column where the cursor is listed. The first non-empty-white font of the first column is moved to the previous column, and the number can be specified to move to the first non-empty white font of the next column to the next column. Move to the following N-column NG Directly with Digital N plus uppercase G Move to NAC 2. Replace and delete When the cursor is positioned in the file, you can use other characters to replace the characters pointed to by the cursor, or from the current cursor Location Delete one or more characters.
For example, the current character NRC pointed to the RC by the C replacement cursor is pointed to by the C replacement cursor, and the first five character x pointed by the C replace the cursor to remove the cursor point to the cursor pointing the cursor pointing. The first n characters 3X Delete the first three characters directed by the cursor to remove the word NDW on the right side of the cursor to remove the n word on the right side of the cursor 3DW Delete the 3 word DB of the cursor on the right side of the cursor to delete the word NDB to delete the cursor left The N word 5db deletes the 5 word DD deletion cursor on the left side of the cursor, and removes the void NDD to delete the N row content, and remove the gap 3DD to delete the 3 line content, and remove the gap 3. Paste and copy from the body to delete The content (such as characters, words or rows) did not really lose, but were cut and copied to a memory buffer. The user can paste it into the specified location in the body. The command to complete this is: p lowercase letter P, paste the contents of the buffer to the back of the cursor P uppercase the letter P, paste the contents of the buffer to the cursor, if the content of the buffer is character or word, direct paste At the front or back of the cursor; if the content of the buffer is a special line, it is pasted on the previous line or next line of the current cursor. Note the case in the above two commands. The VI editor often provides a pair of similar functions in a pair of large, lowercase letters (such as P and P). Typically, the lowercase command operates behind the cursor, and the uppercase command operates in front of the cursor. Sometimes you need to copy a piece of text to a new location while retaining the original location. In this case, you should first copy the specified content (instead of cutting) to the memory buffer. Completion of this operation is: YY Copy Current Direction to Memory Buffer NYY Copy N row content to memory buffer 5YY Copy 5 line content to memory buffer 4. Searching strings, like many advanced editors, VI provides Powerful string search function. To find the location of the specified word or phrase in the file, you can search directly with VI without having to perform manual manual. Search method is: Type characters /, followed by the string to search, and press Enter. The edit program performs a forward search (ie, the end of the file), and then stops the cursor to the beginning of the string after finding the specified string; type n command to continue search, find out the next appearance next time position. Use characters to replace /, reverse search (in the beginning of the document). For example: / STR1 proceeds to search string str1 n, finds the next time the STR1 string appears? STR2 reverse search string STR2 No matter how the search direction, the search work will be looped when the end of the file is reached. The other end of the file continues. 5. Undo and repeat the process of editing the document, to eliminate the consequences of an error editing command, can use the undo command. In addition, if the user wishes to repeat the editing commands performed in front of the new cursor position, you can use a repetition command. u The result of the previous command. Repeat the last modified command 6. Text Select VI to enter a mode that becomes Visual, in which user can use the cursor mobile command to select text, then execute Other editing operations, such as delete, copying, etc. v-character selection command V line selection command # demo # 1.6.3 Insert mode 1. Enter the insert mode After proper positioning the cursor in edit mode, you can switch to the insert mode: i Input the body A on the left side of the cursor on the right side of the cursor Enter the text o The next line of the cursor is in the row of the cursor. Add a new line of rows in the cursor, add new row I. In the beginning of the cursor, enter the head. In the end of the cursor, enter the body. The text is introduced. Simple method for pattern.
There are also some commands that allow first to delete a body before entering the insert mode, thereby implementing the body's replacement. These commands include: s The character NS pointed by the input body ns by the input body NS replaces the cursor right side N-character CW with the input body side NCW with the input body side NCW with the input body to replace NS. N The word Cb replaces the word NCB on the left side of the word Cb by the input body NCB replaces the N-line CD on the left side of the cue on the left side of the N-line NCD, the NCD is replaced with the input body, the N-row C $ input. The body is replaced from the cursor to all characters C0 at the end of the bank from the beginning to all characters from the beginning to the cursor. 2. Exit the insert mode exit the insert mode, press the ESC button or the combination key Ctrl [. # Demo # 1.6.4 Command Mode In the VI command mode, a complex command can be used. In editing mode, type ":", the cursor jumps to the last row of the screen and displays the colon there, and has entered the command mode. Command mode is also known as "Live Mode", and the contents of the user are displayed on the last line of the screen, press the Enter key, the VI execute command. 1. Exit Command You can exit the VI editor with the zz command in editing mode, which saves the modification of the text to overwrite the original file. If you only need to exit the editor, not to save the edited content, you can use the following command:: Q! Q! Wash all modifications, exit Edit 2. Ring and file editing One line has its own line number, with the following command to move the cursor to the specified line:: Migrate the cursor to the NT line command mode, which can specify the line number range of the command operation. The value is used to specify the absolute line number; the character "indicates the line number where the cursor is located; the character mens" $ "indicates the line number of the last line of the body; simple expressions, such as" " 5" means the current line down Chapter 5. For example: 345 Move the cursor to 3455 line: 345W File Write the 345th line to the File file: 3, 5W File Write the third line to the 5th line of File file: 1, .w file will The current line writes the file file:., $ W File Writes the File file to the last line:.,. 5W file starts from the current line to write the 6-line content into the file file: 1, $ w File will all content Write the file file, equivalent to: w file command In command mode, allow you to read the body from the file or write the text into the file. For example: W Write the contents of the edited to the original file to save the intermediate result of the edited: WQ writes the contents of the edited content into the original file and exits the editor (equivalent to the zz command): w File writes the contents of the edited to File File, keep the content of the original file unchanged: a, BW file writes the contents of the line A to the B row into the file file: r file reads the contents of the file file, insert the back of the current cursor in the line: e File Editor New file file instead of the original content: f file Rename the current file to file: f Print the current file name and status, such as the number of files, the line number where the cursor is located, etc. 3. String Search give a string, you can Arrive at the specified line by searching the string. If you want to perform a forward search, place the string to be searched between two "/"; if you want to reverse search, place the string between two "?".
For example: / STR / forward search, move the cursor to the next line containing the string STR:? STR? Reverse search, move the cursor to the previous line: / STR / W File positive Search, and write the first row of string STR to File files: / str1 /, / str2 / w file forward search, and write a row containing strings STR1 to a row containing string Str2 4. Text replacement: The S command can realize the replacement of the string. Specific usages include: S / STR1 / STR2 / with string STR2 standby string STR1: S / STR1 / STR2 / G in the row S / STR1 / STR2 / G with string STR2 standby strings Str1:., $ S / STR1 / STR2 / G Replace the text of the text to the end to the end to the end of all appearance strings string STR1: 1, $ S / STR1 / STR2 / G with string STR2 Str1: g / STR1 / S / / STR2 / G function can be seen from the above replacement command: g is placed at the end of the command, indicating that each appearance of the search string is replaced; does not add G, indicating that only the first appearance of the search string Replace; g is placed at the beginning of the command, indicating that all the rows containing the search string in the body are replaced. 5. Delete the body in command mode, you can also delete the content in the body. For example: D Delete the cursor in line: 3D Delete 3 lines:., $ D Delete the current line to the end: / str1 /, / STR2 / D Delete all rows from strings STR1 to STR2 6. Recovered file VI When editing a file, another temporary file will be generated, the name of this file is usually. Start, and end with .swp. When VI is properly exited, the file is deleted, if an unexpected exit, without saving the latest modification of the file, you can use the recovery command:: Recover recovery file can also utilize the -R option when the VI is started. # Demo # # demo # 1.6.5 Options Set to control different editing features, VI provides a lot of internal options. Utilize: The set command can set the option. The basic syntax is:: Set Option Settings Option Option Options include: AutoIndent Setting this option, the body is automatically indented to ignorecase settings this option, then ignore the difference between the upper and lower cases of the rule expression Number settings this option, display the body The line number RULER sets this option, the cursor is displayed at the bottom of the screen, and the position of the column TabStop sets the number of spaces that tab the Tab key. For example: SET TABSTOP = N, N defaults to 8 mK Save the option in the current directory. EXRC file # 1.6.6 SHELL Switch When editing the body, use the shell switch command provided in VI command mode without exiting VI can execute the Linux command, which is very convenient. The syntax format is::! Command, return to VI after the shell command Command, in the edit mode, type K, can command the VI to find the man page where the cursor is located, which is equivalent to running the man command. # Demo # 1.6.7 VIM and GVIM's advanced feature Vim represents VI Improved, like its name, the Vim is present as a standard UNIX system VI editor raised version. In addition to providing the same power as the VI editor, VI is provided with multi-level recovery, command line history, and command and file name completion.