在vim中,如何仅在匹配字符串的特定行上替换单词?例如,我有
replace here: foo
but not here: foo
replace again here: foo
Run Code Online (Sandbox Code Playgroud)
我想,以取代foo
与bar
在那里的字符串的所有行replace
被发现,即输出应该是
replace here: bar
but not here: foo
replace again here: bar
Run Code Online (Sandbox Code Playgroud)
:/replace/s/foo/bar/
Run Code Online (Sandbox Code Playgroud)
工作,但它只在匹配的第一行进行替换replace
.如何将其扩展到整个文档?
您可以使用g
命令(全局)在多行中更改它:
:g/replace/s/foo/bar/
Run Code Online (Sandbox Code Playgroud)