In linux, vi is used to replace characters-general Linux technology-Linux programming and kernel information. The following is a detailed description. In vi/vim, you can use the: s command to replace the string. In the past, I used to replace it with the editing software. Today I found that there are many ways to write this command (vi is really powerful, and there are still a lot to learn). I recorded several methods here to facilitate future queries.
: S/well/good/Replace the first well in the current row with good
: S/well/good/g replace all of the current row well as good
: N, $ s/well/good/Replace the first well from row n to row n as good
: N, $ s/well/good/g Replace the n-th row and start to the last row.
N is a number. If n is., it indicates starting from the current row to the last row.
: % S/well/good/(equivalent to: g/well/s // good/) Replace the first well in each row with good
: % S/well/good/g (equivalent to: g/well/s // good/g) replace all
You can use # As the separator. The/in the middle will not be used as the separator.
: S # well/# good/# Replace the first well/in the current row with good/
: % S #/usr/bin # g
You can replace all the paths/usr/bin in the file with/bin.
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