Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在unix/vim中,如果行包含某些文本,则替换某些文本_Unix_Vim - Fatal编程技术网

在unix/vim中,如果行包含某些文本,则替换某些文本

在unix/vim中,如果行包含某些文本,则替换某些文本,unix,vim,Unix,Vim,例如,给定文本: source: today is monday target: tomorrow is monday 如果行中包含'target',我想用'sunday'替换'monday',您可以在模式中使用它将匹配的开始设置在所需字符串之前: :%s/target.*\zsmonday/tuesday/ 另一种可能性(可读性稍差)是使用look-behind断言: :%s/\(target.*\)\@<=monday/tuesday/ :%s/\(target.*\)\@

例如,给定文本:

source: today is monday  
target: tomorrow is monday 
如果行中包含
'target'
,我想用
'sunday'
替换
'monday'
,您可以在模式中使用它将匹配的开始设置在所需字符串之前:

:%s/target.*\zsmonday/tuesday/
另一种可能性(可读性稍差)是使用look-behind断言:

:%s/\(target.*\)\@<=monday/tuesday/

:%s/\(target.*\)\@使用global,
:g
和普通替换,
:s

:g/target/s/monday/tuesday/g
有关更多帮助,请参阅:

:h :s
:h :g
该Q可能更适用于S.E.相关站点或。使用Q底部的
标志
链接,让主持人移动它。请不要在两个不同的网站上发布相同的Q。在这里发布更多Qs之前,请阅读和。祝你好运