A detailed explanation about the vi command under Linux

The basic concept of vi
  substantially vi can be divided into three operating states, namely, command mode (Command mode), insert mode (Insert mode) and bottom command mode (Last line mode),
  the function to distinguish each mode is as follows:
  1. the Comand mode: delete screen control cursor movement, a character or a cursor, a moving section and a copy to the next Insert mode, or the Last line mode.
  2. Insert mode: Only in Insert mode, the text is available to do data entry, press Esc, etc. can back Comand mode.
  3. Last line mode: to store files or leave the editor, editing environment can also be provided, such as finding strings, lists the line number and the like.
  However, vi can be simplified into two modes, i.e. the Last line mode is also counted MODE Command, the Command and vi into Insert mode.
  The basic operation of vi
  ? vi entered
  in the system prompt type vi and the file name, you can enter the vi full-screen editing screen:
  $ vi testfile
  It should pay particular attention to is that after you have entered is in vi under "Command mode", your to switch to Insert mode to enter text.
  Initial users will want to use vi to use the cursor keys to move up and down, the result has been called the computer, put their gas half to death, so after entering vi, the first not to tamper with,
  convert them later into Insert. ? Insert mode switches to edit files in the Command mode by 'i', 'a' or 'o' can enter Insert mode triple bond.
  At this time you can start entering text.
  i: insert, insert text input from the current location of the cursor.
  a: increase, the next word of the current cursor start typing.
  o: insert a new row, enter the text from the beginning of the line.
  ? Insert switch → Command mode, press the Esc key
  you are currently in Insert mode, you can only have been typing. If you find a typo, I want to move back with the cursor keys, delete the word,
  we must press the ESC key to switch back to Command mode, and then delete the text.
  ? Leave vi and save the file
  in the Command mode, press the colon ":" Type into the Last line mode, for example:
  : w filename (enter "w filename", the article will be credited to the designated file name filename)
  : WQ (enter " wq ", as it has been testfile specify the file name when entering it, it will be written testfile and leave vi)
  :! q (input"! q ", forced to leave and abandon the edited file)
  the command list of the MODE function key
  in command mode instruction introduction after, the instruction followed by the "common" words function keys, represents the more common vi commands,
  the reader is that you must learn and remember.
  (1) I, a, o into the switching Insert mode. [Super Common]
  (2) move the cursor
  vi can be directly with the cursor keys on the keyboard to move around, but the formal vi is lowercase letters
  h, j, k, l, respectively, to control the cursor left, down, up, right move one space.
  Press Ctrl + B: move back one screen. [Common]
  Press Ctrl + F: the screen to move a forward. [Used]
  Press Ctrl + U: screen moving back half a page.
  Press Ctrl + D: move the screen forward half a page.
  Press 0 (zero): the beginning of the movement of the article. [Used]
  by G: to move to the end of the article. [Used]
  Press w: the cursor jumps to the beginning of the next word. [Used]
  Press e: cursor jumps to the next word in the suffix.
  Press b: the cursor back to the beginning of the last word.
  By $: end of the line to move the cursor line. [Common]
  Press ^: The first non-blank character to move the line.
  Press 0: position to the beginning of the line. [Used]
  Press #: # moved to the first position of the line, for example: 51,121. [Used]
  (3) Delete character
  x: each time the cursor position back to delete a character. [Ultra Common]
  #x is: For example, to delete the cursor position behind 6x Table 6 characters. [Common]
  the X-: characters of X, each time you press delete the previous position of the cursor one character.
  #X: for example, 20X table delete the previous position of the cursor 20 characters.
  dd: Delete cursor line. [Ultra Common]
  #dd: e.g., 6dd Table 6 rows of the number of characters to delete from the line where the cursor down. [Used]
  (4) Copy
  yw: the suffix to the character copied into the buffer at the cursor.
  (And like the opposite function # x, # X's)
  P: Paste into the character in the cursor position buffer (instruction 'yw' and 'p must be used with).
  yy: copy cursor line. [Super popular]
  p: copy a single line to the place you want to paste it. (Instruction 'yy' and 'p' must be used with)
  #YY: As: 6yy character 6 indicates the copy number of lines from the line where the cursor down. [Common]
  the p-: copy multiple lines to place you want to paste it. (Instruction '#yy' and 'p' must be used with)
  "Ayy: Copy line into buffer a, vi to provide buffer function, there will be common data buffer
  " ap: The data in buffer A paste.
  "B3yy: three rows of data into the buffer b.
  " B3P: The present data buffer b paste
  (5) substituted
  r: replace the character at the cursor: [Common]
  R & lt: substituted until you press Esc character.
  (6) Recovery (Use the undo) on a command
  u: If you misuse an instruction can immediately press u, a return to the operation. [Ultra Common]
  : once the instructions may be repeatedly performed.
  (7) Change
  cw: Change the word at the cursor to the suffix $ place.
  c # w: e.g., c3w changes on behalf of three words.
  (8) Jump to a specific row
  Ctrl + G: lists the line number of the cursor line.
  #G: for example, 15G, move the cursor to indicate the article 15 of the first trekking. [Used]
  under the Last line mode command introduction
  before the reader you want to use Last line mode, please remember to press the Esc key to confirm you are already in the next Command mode, press the colon ":" "?" Or "/" or
  triple bond one key to enter the Last line mode.
  1. List line number
  set nu: Enter "set nu", lists the line number in front of each line of the article.
  2. Go to a line in the article
  #: pound represents a number in the Last line mode prompt ":" Before entering a number, then press Enter will jump to the line,
  such as: 15 [Enter] will jump the first line of article 15. [Common]
  3. Look for the string
  / Keywords: press /, then enter the word you're looking for, if not first find your keywords with much as possible, you can always press the n you want to be looking down the far keyword.
  ? Keywords: press, then enter the word you're looking for, if not the first to find the keywords you want, you can press n will be looking forward to the date the keywords you want?.
  4. substitution string
  1, $ s / string / replae / g: In the last line mode input string character string "1, $ s / string / replace / g" will be substituted to replace the text string,
  wherein 1, $ s search interval refers to the meaning of the article from start to finish, g it is a complete replacement for having to confirm.
  % s / string / replace / c : the same text will replace string string string is substituted, the above instructions and different places,% s and 1, $ s the same function,
  C is an alternative to showing before It must reconfirm whether to replace.
  1,20s / string / replace / g: the string between 1-20 replaced relpace string line.
  5. save the file
  w: in the last line mode prompt ":" w according to the file before the deposit. [Super popular]
  #, # W filename: If you want the removal of a section of the article, save as another file, can use this command # represents the line number, for example, 30,50 w nice,
  the first 30 to 50 lines of the article you are editing to save nice this document.
  6. leave
  q: q Press the left, sometimes if you can not leave vi, can be used with ":! Strong home away from vi, such as" q "!
  QW: When is generally recommended to leave, together with the use of w, can also save files so leave

Above is borrowed from the page https://wenda.so.com/q/1486495486499987

Guess you like

Origin www.cnblogs.com/007-001/p/11741631.html