Summary of common Linux commands-vi editor

Source: Internet
Author: User
Summary of common Linux Commands & mdash; vi editor vi is a powerful editor on the linux command line interface. Three command modes of Vi: you can use vi commands to manage files, such as moving optical objects, deleting and moving characters and lines, insert mode: you can edit files, and last line mode: yes... summary of common Linux commands-vi editor vi is a powerful editor on the linux command line interface. Three command modes of Vi: you can use vi commands to manage files, such as moving optical objects, deleting and moving characters and lines, insert mode: you can edit files, and last line mode: save, exit, and set the editing environment. run the vi filename command to open or create a file and place the cursor in the first line vi + n filename: open the file, place the cursor at the beginning of line n vi + filename: open the file and place the cursor at the beginning of line n vi-r filename: a system crash occurred when vi was being edited last time, restore filename vi +/pattern filename: open the file and place the cursor at the first string matching pattern (not used in RHEL5 test) vi filename .... filename: open multiple files, edit them one by one (test in RHEL5 is not used) exit vi command: w save: w filename save as filename File: q exit vi, if the file has been modified, you are prompted Save: wq is saved and exited, that is, w and q are merged. w and q: x are used to save the current file and exit. this is equivalent to wq: q, which exits vi: q! If you do not save the file and exit vi, moving the cursor below the command takes effect in command mode. H or space move the cursor to the left one character l or Backspace move the cursor to the right one character k or Ctrl + p move the cursor up one line j or Ctrl + n move the cursor down one line ^ Move the cursor to the beginning of the row $ move the cursor to the end of the row H move the cursor to the first character of the top line L move the cursor to the end character of the last line of the screen Ctrl + B move the screen back Ctrl + f screen move forward one screen Ctrl + u screen move back half screen Ctrl + d screen move forward half screen M: move the cursor to the middle line of the screen Enter: Move the cursor down a row w or W: Move the cursor right to the next word to the first B or B: Move the cursor left to the first word to e or E: move the cursor right to the next word to the end of the word fc move the cursor to the next c character in the same line (c can be any character) fc moves the cursor to the first c character in the same row. tc moves the cursor to the first c character in the same row. Tc moves the cursor to the next c character in the same row * | move the cursor to column * ("|" is a vertical line with the symbol, * represents an integer) * l cursor Move * characters to the right ("l" is a small character with the character L, * represents an integer) * h move the cursor to the left * character * k move the cursor up * character * j move the cursor down * character) move the cursor to the end of the sentence (move the cursor to the beginning of the sentence) move the cursor to the beginning of the paragraph {move the cursor to the end of the paragraph * G: Move the cursor to the first line * +: Move the cursor down * line *-: move the cursor up * line * $: move cursor to the end of line * insert text command description I insert text before the current character I insert text at the beginning of line a add text after the current character A add text at the end of line o Add text after the current line insert an empty line O insert an empty line R in front of the current line enter a text delete File command description x delete the character at the cursor position X delete the character before the cursor position x delete * characters, * character d starting from the current cursor $ delete content from the current cursor to the end of the line d ^ delete content from the current cursor to the beginning of the line dd delete the current row * d delete * row, delete the current row and the last *-1 row dw delete a word * dw delete * word text replace command R replace the current word The character * r replaces the character * R starting from the current cursor with the input character and the character R following the current character until the newly entered text * is pressed by the ESC key * r, for example, 3Rab will be replaced by "ababab. cc replaces the entire line of C with the content that will be input to replace all content from the cursor to the end. cb replaces the content from the beginning to the cursor. The word [rang] s/pattern/string [option] Rang in which cw replaces the cursor indicates the search range. the default value is all text. For example, 2 and 4 indicate to replace the content of the rows from 2 to 2. Pattern is used to specify the content to be replaced. it can be the regular expression Stirng, which is a string used to replace pattern. [option]: c. ask before each replacement, ask the user to confirm that e does not display the error g to replace the characters in the specified range. if replacement is not performed, I will not be asked. the replacement is case-insensitive [example] in Test. replace Test with test [python] [root @ localhost rootfile] # vi Test. java public class Test {public static void main (String args []) {System. out. println ("Hello World! ") ;}} S/Test/test result: public class Test {public static void main (String args []) {System. out. println (" Hello World! ") ;}} Enter"/"or"? "in command mode. Switch to the last line mode. /Pattern search the end of the file at the beginning of the cursor. if the end of the file is reached, it starts from the file header? At the beginning of the pattern cursor, search for the pattern at the beginning of the file. if a file header is found, start from the end of the file/pattern/+ * Stop the cursor on the * line behind the row containing pattern/-* Stop the cursor on the * line before the row containing pattern * last n repeat the previous search command in the original search direction N repeat the previous search command in the opposite direction copy and paste yw copy the word at the cursor to the buffer * yw copy from the current word * copy the row where the cursor is located to the buffer * yy copy the row where the cursor is located * row to the buffer y $ copy the content from the cursor position to the end of the row to the buffer y ^ copy the cursor the content starting from the first character to the beginning of the line to the buffer zone yG copy the content from the row where the current cursor is located to the end of the file to the buffer zone lyG copy the row where the current cursor is located to the file header content to the buffer zone p buffer to the right of the current cursor, if the buffer content is a row, copy the row P below the cursor and paste the buffer content to the left of the current cursor. if the buffer content is a row, copy the row above the cursor to repeat In this way, repeated operations are often performed when you use vi to edit text content. To repeat a command, you only need to press "." in command mode. the base operation is for the current position of the cursor. The undo command is used to cancel an error and return it to the previous state. To repeat a command, you only need to press "u" or "U" in command mode.
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.