搜索并替换一个确切的字符串,无论是否被包围或在另一个词中
Search and replace an exact string, no matter if surounded or within another word
我想找到一个确切的字符串,它可以在文本或单词中的任何位置。
.test_block
.test_block--yellow
.another_test_block
.block_test_block
应该是
.test_div
.test_div--yellow
.another_test_div
.block_test_div
当 运行 一个 s/test_block/test_div/c
。左边的例子不起作用。它确实增强了 /g
标志。任何人有想法,为什么这不适用于确认 (/c
)?
你做得对,只要确保你使用命令运行的范围。例如:
:%s/test_block/test_div/g " every line
:10,20s/test_block/test_div/g " lines 10 to 20
如果您想在全球范围内进行确认并进行确认,请包括两个标志:
:%s/test_block/test_div/gc
我想找到一个确切的字符串,它可以在文本或单词中的任何位置。
.test_block
.test_block--yellow
.another_test_block
.block_test_block
应该是
.test_div
.test_div--yellow
.another_test_div
.block_test_div
当 运行 一个 s/test_block/test_div/c
。左边的例子不起作用。它确实增强了 /g
标志。任何人有想法,为什么这不适用于确认 (/c
)?
你做得对,只要确保你使用命令运行的范围。例如:
:%s/test_block/test_div/g " every line
:10,20s/test_block/test_div/g " lines 10 to 20
如果您想在全球范围内进行确认并进行确认,请包括两个标志:
:%s/test_block/test_div/gc