LInux Notes (3) vi

1. The basic concept of 
  vi Basically, vi can be divided into three states, namely command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows: 
    1) Command line mode (command mode) 
  controls the movement of the screen cursor, deletes characters, words or lines, moves and copies a section and enters Insert mode, or goes to last line mode. 
    2) Insert mode (Insert mode) 
  Only in Insert mode, text input can be done, press the "ESC" key to return to the command line mode. 
    3) The bottom line mode (last line mode) 
  saves the file or exits vi, and can also set the editing environment, such as searching for strings, listing line numbers...etc. 

    But generally we simplify vi into two modes when we use it, that is, the last line mode is also counted as the command line mode (command mode). 
2. Basic operations of vi 
a) 
    Enter vi and enter vi and the file name at the system prompt, then enter the vi full-screen editing screen:
   $ vi myfile 
  But there is one thing to pay attention to, that is, after you enter vi, you are in the "command line" Mode (command mode)", you have to switch to "Insert mode (Insert mode)" to be able to enter text. People who use vi for the first time will want to use the up, down, left, and right keys to move the cursor first. As a result, the computer keeps beeping and beeps, which makes me half-dead. So after entering vi, don't move around, switch to "Insert mode" and then talk about it. ! 

b) Switch to Insert mode to edit the file 
  In the "command mode (command mode)" press the letter "i" to enter the "insert mode (Insert mode)", then you can start typing text. 

c) Insert switch 
  You are currently in "Insert mode", you can only enter text all the time, if you find that you have entered a wrong word! If you want to use the cursor keys to move back and delete the word, you must first press the "ESC" key to go to "command mode" and then delete the word. 

d) Exit vi and save the file 
  In "command mode (command mode)", click the ":" colon key to enter "Last line mode", for example: 
: w filename (input "w filename" to convert the article to the specified file
: wq (input "wq", save and exit vi) 
q! (input q!, force quit vi without saving) 

3. Command mode (command mode) function key  1).        Press "i"
in insert mode 
"Switch to enter the insert mode "insert mode", press "i" to enter the insert mode to start inputting the file from the current position of the cursor;
  press "a" to enter the insert mode, to enter the text from the next position of the current cursor position; 
  After pressing "o" to enter the insert mode, a new line is inserted, and the text is entered from the beginning of the line. 

2). Switch from insert mode to command line mode and 
      press "ESC" key. 

3). To move the cursor 
  vi, you can directly use the cursor on the keyboard to move up, down, left and right, but the regular vi uses lowercase English letters "h", "j", "k", "l" to control the cursor left, down, Move up and right by one space. 
  Press "ctrl" + "b": the screen moves to "back" one page. 
  Press "ctrl" + "f": the screen moves to "forward" one page. 
  Press "ctrl" + "u": the screen moves to the "back" half page. 
  Press "ctrl" + "d": the screen moves to the "forward" half page. 
  Press the number "0": move to the beginning of the article. 
  Press "G": move to the end of the article. 
  Press "$": move to the "end of line" of the line where the cursor is located. 
  Press "^": move to the "start of line" of the line where the cursor is located 
  Press "w": the cursor jumps to the beginning of the next word 
  Press "e": the cursor jumps to the end of the next word 
  Press "b": the cursor returns to Press "#l" at the beginning of the previous character 
  : the cursor moves to the #th position of the line, such as: 5l, 56l. 

4). Delete the character 
  "x": Each time it is pressed, one character "behind" the cursor position is deleted. 
  "#x": For example, "6x" means to delete 6 characters "behind" the cursor position. 
  "X": uppercase X, each time you press it, delete the "preceding" character at the cursor position. 
  "#X": For example, "20X" means to delete 20 characters "before" the cursor position. 
  "dd": Delete the line where the cursor is located. 
  "#dd": delete #line 5) from the line where the cursor is located 


  Copy "yw": Copy the characters from the cursor to the end of the word into the buffer. 
  "#yw": Copy # words to the buffer 
  "yy": Copy the line where the cursor is located to the buffer. 
  "#yy": For example, "6yy" means to copy 6 lines of text "counting down" from the line where the cursor is located. 
  "p": Paste the characters in the buffer to the cursor position. Note: All copy commands related to "y" must be combined with "p" to complete the copy and paste function. 

6). Replace 
  "r": replace the character where the cursor is. 
  "R": Replace the character at the cursor position until the "ESC" key is pressed. 

7). Reply to the last operation 
  "u": If you execute a command by mistake, you can press "u" immediately to return to the previous operation. Multiple replies can be performed by pressing "u" multiple times. 

8). Change 
  "cw": change the word where the cursor is located to 
  "c#w" at the end of the word: for example, "c3w" means to change 3 words 

9). Jump to the specified line 
  "ctrl" + "g" column Displays the line number of the line where the cursor is located. 
  "#G": For example, "15G", which means move the cursor to the beginning of the 15th line of the article. 
4. Introduction to commands in Last line mode 
  Before using "last line mode", please remember to press the "ESC" key to confirm that you are already in "command mode", and then press the ":" colon to enter the "last line mode" ". 

A) List line numbers 

 "set nu": After typing "set nu", line numbers are listed before each line in the file. 

B) Jump to a line 

 "#" in the file: The "#" sign represents a number, enter a number after the colon, and then press the Enter key to jump to the line, such as entering the number 15, then press Enter, will jump to line 15 of the article. 

C) find characters 

 "/Keyword": Press the "/" key first, and then enter the character you want to find. If the keyword you are looking for the first time is not what you want, you can keep pressing "n" to find the key you want later. until the word. 

 "?Keyword": Press the "?" key first, and then enter the character you want to find. If the keyword you are looking for for the first time is not what you want, you can keep pressing "n" to find the key you are looking for. until the word. 

D) Save the file 

 "w": Enter the letter "w" in the colon to save the file. 

E) Exit vi 

 "q": Press "q" to exit. If you cannot leave vi, you can forcefully leave vi after "q" followed by a "!". 

 "qw": It is generally recommended to use it together with "w" when leaving, so that the file can be saved when exiting.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327093858&siteId=291194637