在UNIX/VIM,替代某些文本,如果行中包含某些文字
问题描述:
例如,给定文本:在UNIX/VIM,替代某些文本,如果行中包含某些文字
source: today is monday
target: tomorrow is monday
我想替换'monday'
与'tuesday'
如果行包含'target'
。
答
使用全局,:g
和正常替换,:s
。
:g/target/s/monday/tuesday/g
如需更多帮助,请参见:
:h :s
:h :g
这种问答** **可能是在S.E.更合适相关网站http://superuser.com或http://vi.stackexchange.com。使用Q底部的'flag'链接并请主持人移动它。请不要在2个不同的网站上发布相同的Q.在此处发布更多Q值之前,请阅读http://stackoverflow.com/help/how-to-ask http://stackoverflow.com/help/dont-ask和http://stackoverflow.com/help/mcve。祝你好运 – shellter