viThe editor is allUnixandLinuxThe Standard Editor under the system is alsoLinuxThe most basic text editor in, after learning it, you willLinuxIn the world of freedom
viIt can be divided into three states: command mode（command mode）, insert mode（Insert mode）Bottom row mode（last line mode）, the functions of each mode are distinguished as follows:
be careful：get intoviAfter that, it is in command line mode（command mode）, to switch to insert mode（Insert mode）To enter textMake text editing
(1) Command line modecommand mode
Controls the movement of the screen cursor and the deletion of characters, words or lines,PressESC keyget intoCommand line mode
- viIn command line modeYou can directly use the cursor on the keyboard to move up, down, left and right, but it is normalviIt is a lowercase English letter “h」、「j」、「k」、「l“, respectively control the cursor to move one grid left, down, up and right.
- Pressctrl」+「b」：Turn one page to the beginning of the document。
- Pressctrl」+「f」：Turn one page to the end of the document。
- Pressctrl」+「u」：Turn the first half page of the document。
- Pressctrl」+「d」：Turn half a page to the end of the document。
- By number0」：cursorMove toLineBeginning ofposition。
- PressG“: move to the end of the article.
- Press$“: move to the line where the cursor is located“End of line“。
- Press^“: move to the line where the cursor is located“Line beginning”
- Pressw“: the cursor jumps to the beginning of the next word
- Presse“: the cursor jumps to the end of the next word
- Pressb“: the cursor returns to the beginning of the previous word
- Pressdd」 :Delete the data of the row where the cursor is located
- Pressnumberdd」 :Deletes the number of lines from the cursornthat ‘s ok , such as10dd(delete the line where the cursor is located)10Row data)
- Pressyy」 :Copy a row of data where the cursor is located
- Pressnumberyy」 :Copy the number of lines after the cursor positionnthat ‘s okdata , such as10yy(copy the line of the cursor)10Row data)
- Pressp」 :Paste the copied value, equivalent towindowYesctrl+v
- Pressu」 :Cancel operation, equivalent towindowYesctrl+zWithdraw operation
(2) Insert modeInsert mode
Only inInsert modeText input can only be done under.
There are three ways to enter the insertion mode:
- Pressi」keyAfter entering insert mode, press“i”After entering the insertion mode, input the file from the current position of the cursor;
- Pressa」keyAfter entering the insertion mode, input text from the next position where the current cursor is located;
- Presso」keyAfter entering the insert mode, insert a new line and input text from the beginning of the line.
(3) Bottom row modelast line mode
Save or exit the filevieditor , list line numbers, etc, press firstPress ESC to confirm that you are in command line mode, and then press English:keyEnter the underlying mode。
- 「set nu」：EnterAfter “set Nu”, the line number will be listed in front of each line in the file。
- 「#」：「#The “” sign represents a number,In underlying modeEnter a number and press enter to jump to this line, such as entering a number15If you press enter again, you will jump to the second page of the article15that ‘s ok.
- 「w」 : inputEnter the letter ”w」 JustYou can save the edited file.
- 「q」 : press “Q” to exit. If you can’t leave VI, you can follow “Q” with a “!” Indicates that you are forced to leave the VI editor. Such as: q!
- 「wq“: it is generally recommended to leave with”w」 Use together so that you can save the file when you exit.For example:wq
- 「w filename“: save the file being edited. Save the file asfilename。 asw Test.txt (save the edited file as test.txt file)
- 「wq filename“: save the file being edited. Save the file asfilename,And launchviEditor. aswq Test.txt (save the edited file as test.txt file and exit the editor)
- 「/Keyword: to search for characters, click/”Key, and then enter the character you want to find. If the keyword you find for the first time is not what you want, you can always press” n “Look backUntil the keyword you want.
- 「?Keyword: to search for characters, click?」 Key, and then enter the character you want to find. If the keyword you find for the first time is not what you want, you can press “n” all the timeLook forwardUntil the keyword you want.