Vi replacement, vi

Source: Internet
Author: User

Vi replacement, vi

In the vi editor, you can use the: s command to replace strings. The specific usage is as follows:

1.: s/str1/str2/replace str1, the first character string that appears in the line with string str2;

2. s/str1/str2/g: replace str1 with string str2;

3.:., $ s/str1/str2/g. Use string str2 to replace all the strings str1 from the current row to the end of the body;

4.: 1, $ s/str1/str2/g replace str1 with string str2;

5. The functions of g/str1/s // str2/g are the same as those of 4.

At the end of the command, it indicates to replace each appearance of the search string. If no g is added, it means to replace the first appearance of the search string. g is placed at the beginning of the command, replaces all rows in the body that contain search strings.


Replacement in vi

: % S/stLoanCom. memocode/stLoanCom. xxxxxxx/g
Sed can be used. sed's/stLoanCom. memocode/stLoanCom. xxxxxxx/G' file
Multiple files
For I in *. c; do
Sed's/stLoanCom. memocode/stLoanCom. xxxxxxx/G' "$ I"> file2
Mv file2 "$1"
Done

In linux, how does one replace the same character with the vi editor?

1) Single Character replacement: In command mode, place the cursor in the character to be replaced, press r, and then press the required character;
2) Replace string: $ s/string/replae/g in command mode
Replace the full-text string with the replace string, where 1 and $ s indicate that the search interval is from the beginning to the end of the article, and g indicates that all replications do not need to be confirmed.
% S/string/replace/c: replace the full-text string with the replace string, which is different from the preceding command: % s and 1, $ s is the same function, and c indicates that you must confirm whether to replace it before replacement.
1, 20 s/string/replace/g: replace the string between 1 and 20 lines with the relpace string.

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.