Vi editor commands in Linux

Source: Internet
Author: User
UNIX editors include ex, sed, and vi, among which vi is the most widely used. Vi is a program for creating and modifying text and data objects. The difference between him and the word processing program and the desktop publishing program is that he only processes plainASCII text and has no format information. The vi editor has three processing methods...
UNIX editors include ex, sed, and vi, among which vi is the most widely used. Vi is a program for creating and modifying text and data objects. The difference between him and the word processing program and the desktop publishing program is that he only processes plain ASCII text and has no format information. The vi editor has three basic text processing modes:
● Normal mode: When a file is processed by vi, the normal mode is used as soon as the file is entered. In this mode, you can move the cursor by pressing the upper, lower, and lower buttons. you can use "delete character" or "delete entire line" to process the file content, you can also use copy and paste to process file data. ● Editing mode: in general mode, you can delete, copy, paste, and other actions, but you cannot edit them. After pressing the letters I, I, o, O, a, A, r, R, and so on, the editing mode is displayed. Note that in Linux, after you press the above letter, INSERT or REPLACE appears at the bottom left of the screen, so that you can enter characters in the file. To return to normal mode, you must press Esc to exit the editing mode. Www.2cto.com ● command mode: in general mode, enter ":" or "/" to move the cursor to the last line. In this mode, you can search for data, read, store, replace a large number of characters, exit vi, and display row numbers. Start vi: open or create a file with the vi file name, and place the cursor at the beginning of the line to save the work whether or not to exit vi. Press ESC to check whether vi is in command mode.: W save, but do not exit vi: wq! Save and exit vi: q! Exit vi, but do not save changes: w file name with other file names save: w! The file name is saved in an existing file and overwritten. the following keys of the file move the cursor as follows (first press ESC to enter the command mode ): l or the right arrow to move the cursor to the right h or the left arrow to move the cursor k or the top arrow to move the cursor j or the down arrow to move the cursor down ^ Move the cursor to the first non-blank character in the current row (non-TAB or non-space characters ). # Move the cursor to the end of the current row and stop it on the last character. [row number] G move the cursor to the beginning of the row specified by the row number. If no row number is given, move the cursor to the beginning of the last line of the file www.2cto.com w move the cursor forward to the next word (separated by punctuation marks or blank spaces) W move the cursor forward to the beginning of the next word (non-blank string) B move the cursor back to the previous word (separated by punctuation or blank spaces) b. move the cursor back to the beginning of the previous word (non-blank string). e. move the cursor to the end of the word (the word is a string of letters and numbers separated by punctuation marks or blank spaces) e. move the cursor to the end of the word (the word is a non-blank string). the following keys delete the text as follows: x deletes a character, x delete the nx after the cursor from the current cursor position from the right to delete n characters X delete a character, X delete the nX before the cursor delete n characters from the left from the current cursor position dd delete the current row db delete the former word dw delete from the current cursor position to the end of the word dG delete the current line until the end of the file Ctrl + u delete input text do delete to the beginning of the line d $ delete to the end of the line ndd delete when Enter the insert mode to replace the current cursor character s with the current character and enter the insert mode r to replace the current character and the following characters, until you press the ESC key cw to change to the beginning of the next word cc to modify the entire line cG from the last line of the file to modify the following keys to copy and move the text as follows: yy copy the current row nyy from the current row position start copying n rows p ????????? Copy the temporary data in the next row of the cursor ???????? Copy the temporary data and search for and replace it with:/text ???????? Find the string text from the cursor position? Text ???????? Search for the string text n ?????????? Continue to find the next string (used after entering the search command above) N repeat in the reverse direction: s/text1/text2 search for text1 forward and replace it with text2: m, ns/text1/text2 search for text1 from Row m to line n and replace it with text2: s/texte1/text2/g to search for text1 in the entire file and replace it with text2 to insert text: I before the cursor I after the cursor at the beginning of the current line a at the end of the current line o open A new line under the current line O open a new line on the current line option settings command: all lists all options. set the term. terminal type. ignorance. in the search, ignore the case-sensitive list. display the tab position (Ctrl + I) and the End flag ($) number display row number report Display number modified by the line-oriented command terse display brief warning information other edit command: www.2cto.com .?????????? Repeat the previous command u ?????????? Cancel the previous command Ctrl + l ??????? Refresh the screen: set number ????? The row number of the file is displayed, but the file is not saved: set nonumber ???? Display the removed row number: set ai ???????? Set the starting position of each line (starting from the current position of the cursor): set noai ??????? The starting position of the row to be canceled is set to n1, n2 co n3. copy the content from line n1 to line n2 to line n3: n1, n2 m n3 move content from line n1 to line n2 to line n1: n1, line n2 d delete content from line n1 to line n2 by yanghua812
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.