Implement batch replacement of strings in Vi, while batch replacement of vi strings
Batch replacement of strings in Vi
A. replace all in the file:
% S # abc # def # g (replace all abc files with def)
For example, replace "linuxidc.com" in a text file with "linuxidc.net ":
: % S # linuxidc.com # xwen.net # g (such as # in the file, available/replaced, such as % s/linuxidc.com/xwen.net/g)
B. Partial replacement in the file:
Replace "abc" in 10 to 50 rows with "def"
: S # abc # def # g (if the file contains #, available/replaced,: % s/abc/def/g)
If the above command is followed by c after g, a prompt will be displayed before replacement to confirm the user (conform) whether to replace. For example
: % S # linuxidc.com # linuxidc.net # gc
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.