Linux editor vi Usage Details vi editor is a standard editor for all Unix and Linux systems, which is not inferior to any latest text editor, here is just a brief introduction to its usage and a small part of commands. The vi editor is identical for any version of Unix and Linux systems, so you can learn more about it in any other section about vi. Vi is also the most basic text editor in Linux. After learning it, you will be able to enjoy the free access in the Linux World. 1. The basic concepts of vi can basically be divided into three states: command mode, Insert mode, and last line mode ), the functions of each mode are classified as follows: 1) command line mode: controls the movement of the screen cursor, the deletion of characters, words, or rows, the movement of a certain segment, and the entry of Insert mode, or to the last line mode. 2) The Insert mode can be used for text input only in the Insert mode. Press the ESC key to return to the command line mode. 3) The last line mode saves or exits the file vi. You can also set the editing environment, such as searching strings, listing row numbers, and so on ....... However, we generally simplify vi into two modes in use, that is, the last line mode is also included in the command line mode ). 2. Basic operations on vi a) after entering the vi and file name in the system prompt symbol, go to the full-screen vi editing screen: $ vi myfile, but pay special attention to it, after you enter vi, it is in "command mode". You must switch to "Insert mode" to enter text. People who use vi for the first time will want to move the cursor first with the upper and lower right keys. As a result, the computer keeps beeping and getting angry with themselves. So after entering vi, do not tamper with the mouse, switch to "Insert mode! B) switch to Insert mode. Click "I" under "command mode" to enter "Insert mode) ", then you can start entering text. C. Insert switch: You are currently in "Insert mode", and you can only enter text all the time. If you find that you have entered an error! To move the word back with the light mark key, you must first Press ESC to switch to command mode and then delete the text. D) Exit vi and save the file. In command mode, click ":" colon to enter "Last line mode". For example :: w filename (enter "w filename" to save the article with the specified filename): wq (enter "wq", save the disk and exit vi): q! (Enter q !, Do not save disk force exit vi) 3. command line mode function key 1 ). in insert mode, press I to switch to insert mode. In insert mode, press I to enter insert mode. Then, the input file starts from the current position of the cursor; after you press "a" to enter the insert mode, the text is input starting from the next position where the cursor is currently located. After you press "o" to enter the insert mode, a new row is inserted, enter text from the beginning of the line. 2) switch from insert mode to command line mode and Press ESC. 3 ). move the cursor vi can move up, down, and left directly with the cursor on the keyboard, but the regular vi uses lowercase letters "h", "j", "k", and "l 」, the cursor is controlled to move one cell to the left, down, up, and right respectively. Press ctrl + B to move the screen to the back. Press ctrl + f to move the screen to the front. Press ctrl + u to move the screen to the rear half of the page. Press ctrl + d to move the screen to front. Press the number "0": to move to the beginning of the article. Press G to move to the end of the article. Press "$" to move to "end of line" of the row where the cursor is located ". Press "^": Move to the "Beginning of the line" of the row where the cursor is located press "w": the cursor jumps to the beginning of the next word and press "e 」: move the cursor to the end of the next word and press "B": the cursor returns to the beginning of the previous word and press "# l": the cursor moves to the # position of the row, for example, 5l, 56l. 4). Delete the text "x": each time you press it, delete the "Next" character at the cursor position. "# X": for example, "6x" indicates deleting the "Next" to the cursor position. "X": uppercase X. Each time you press it, the "front" character of the cursor is deleted. "# X": for example, "20X" indicates to delete the "front" of the cursor. Dd: Delete the row where the cursor is located. "# Dd": delete from the row where the cursor is located # Row 5). Copy "yw": copy the character from the cursor to the end of the character to the buffer zone. "# Yw": Copy # words to the buffer zone "yy": copy the row where the cursor is located to the buffer zone. "# Yy": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down. P: place the characters in the buffer to the cursor position. Note: All copy commands related to "y" must work with "p" to complete the copy and paste function. 6) Replace "r": Replace the character at which the cursor is located. "R": Replace the character wherever the cursor goes until you press the "ESC" key. 7). Reply to the previous operation "u": If you mistakenly execute a command, you can immediately press "u" and return to the previous operation. You can perform multiple replies for multiple times by "u. 8 ). change cw: change the word at the cursor to c # w at the end of the word. For example, c3w indicates changing 3 words 9 ). jump to the specified row ctrl + g to list the row number of the cursor. "# G": for example, "15G" indicates moving the cursor to the first row of the article. 4. Before using "Last line mode", remember to press the "ESC" key to confirm that you are already in "command mode", and then press 「: "colon to enter" last line mode 」. A) list the row number "set nu": After Entering "set nu", the row number is listed before each row in the file. B) jump to a line in the file "#": "#" indicates a number, enter a number after the colon, and press the Enter key to jump to this line. For example, enter the number 15, press enter to jump to the second line of the article. C) Search for the character "/keyword": First press the "/" key, and then enter the character you want to search. If the first search keyword is not what you want, you can always press "n" until you find the keyword you want. 「? Keyword: First press 「?」 Enter the character you want to search for. If the keyword you want for the first time is not what you want, you can press "n" until you find the keyword you want. D) save the file "w": Enter the letter "w" on the colon to save the file. E) Exit vi "q": Press "q" to exit vi. If you cannot leave vi, you can follow "q" 「!」 Force exit vi. "Qw": it is generally recommended to use it with "w" when leaving, so that files can be saved when exiting. 5. vi command list 1. The following table lists some key functions in command mode: h move cursor to left one character l move cursor to right one character k move cursor up one line j move cursor down one line ^ move cursor to first line 0 Number "0 ", move the cursor to the beginning of the article G move the cursor to the end of the article $ move the cursor to the end of the line Ctrl + f forward screen Ctrl + B backward screen Ctrl + d forward half screen Ctrl + u back flip half screen I insert character a before the cursor position the next character at the cursor position begins to add o Insert a new line, start from the beginning of the line and enter ESC from the input state to the command State x Delete the character after the cursor # x Delete the # character after the cursor X (uppercase X ), delete character before cursor # X delete character before cursor # character dd Delete row where cursor is located # Row yw copy a word at cursor position # yw copy the cursor position # Word yy copy the line where the cursor is located # yy copy the line from the number of lines where the cursor is located # line p paste u cancel Operation c W. Change the word where the cursor is located # cw change the word where the cursor is located #2. Some commands in the following Table travel command mode w filename store the file being edited as filename wq filename save the file being edited as filename, and exit vi q! Discard all modifications and exit vi set nu to display the row number/or? Search, enter the content n and/or? If the search content is not the keyword, press n or backward (and/) or forward (and? Continue searching until it is found. Note the following when using vi for the first time: 1. After opening a file with vi, it is in command mode )」, you must switch to Insert mode to enter the text. Switch method: click "I" under "command mode" to enter "Insert mode )」, now you can start to input text. 2. After editing, you must switch from the insert mode to the command line mode to save the file. to switch to the mode, Press ESC. 3. Save and exit the file: In command mode, enter wq! (Don't forget the one before wq)