在 vim 中的多行中查找和替换字符串 [英] Find and replace strings in vim on multiple lines
本文介绍了在 vim 中的多行中查找和替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以用 :%s/
替换文件中的字符串,或者 :s/
replace_string>/
在当前行替换.
I can do :%s/<search_string>/<replace_string>/g
for replacing a string across a file, or :s/<search_string>/<replace_string>/
to replace in current line.
如何从 vim 中的选择行中选择和替换单词?
How can I select and replace words from selective lines in vim?
示例:替换 6-10
、14-18
行中的文本,但不替换 11-13
行中的文本.
Example: replace text from lines 6-10
, 14-18
but not from 11-13
.
推荐答案
:&&
命令使用相同的标志重复最后一次替换.您可以为其提供额外的范围(并根据需要连接任意数量):
The :&&
command repeats the last substitution with the same flags. You can supply the additional range(s) to it (and concatenate as many as you like):
:6,10s/<search_string>/<replace_string>/g | 14,18&&
如果你有很多范围,我宁愿使用循环:
If you have many ranges though, I'd rather use a loop:
:for range in split('6,10 14,18')| exe range 's/<search_string>/<replace_string>/g' | endfor
这篇关于在 vim 中的多行中查找和替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文