VI Text Search and replace operation in Linux

Source: Internet
Author: User

"/" is the VI Editor's Mode search command. When you type/, a line appears at the bottom of the screen, and a diagonal shoulder appears at the beginning of the bottom line, and the cursor is placed after the tilt. At this point, you can type the pattern you want to search at the cursor position. After you enter the completion and press ENTER, the editor will begin searching for the pattern you typed from the cursor's location to the end of the file. If the input pattern is found, the cursor will remain on the found pattern. After you find a matching pattern, use the command "n" If you need to search for the next matching pattern, or use the "n" command if you need to find the last matching pattern.

In addition, the "?" command is also a pattern search command. and "/" is the difference between/is from the cursor when
The previous location searches for the end of the file, and the "?" Command searches the file head for the current location of the cursor.

Text substitution operations require the use of a last-line pattern, which means that all text substitution operations commands start with ":".

The format of the text substitution command is:

: S/TEXT1/TEXT2 is used to replace the first "text1" That is searched for the paragraph where the cursor is located with the "Text2";

: s/text1/text2/g is used to replace all "Text1" in the paragraph where the cursor is positioned with "text2";

: m,ns/text1/text2/g is used to replace all "text1" searched to Text2 from the beginning of the M line to the end of n rows. You can use $ to represent the last line, which means "1,$" to replace all eligible characters in the document.

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.