vi vim 删除特殊块中的一个词
vi vim delete a word in a special block
我只想删除注释中的 "go"s,在 vi 或 vim 中。可以告诉我怎么做吗?
/*
the following gos should be deleted: in the comment
go
*/
the following go should not be deleted
go
/*
the following go should be deleted: in the comment
go
and some more words
go
*/
the following go should not be deleted
go
删除后的结果应该是这样的:
/*
the following gos should be deleted: in the comment
*/
the following go should not be deleted
go
/*
the following go should be deleted: in the comment
and some more words
*/
the following go should not be deleted
go
谢谢。
此行适用于您的示例:
%s#/\*\zs\_.\{-}\ze\*/#\=substitute(submatch(0),'go','','g')#
您可能想在 vim 的帮助文档中查看一些项目:
:h \zs
:h \ze
:h \_.
:h /star
:h :s\=
:h substitute(
你可以试试这个:
g/\/\*/.,/\*\//s/\<go\>//g
g/<pattern>/
- 匹配包含给定模式的行,在本例中是注释的开头
.,/<patter>/
- 从当前行到匹配模式的下一行执行以下 ex 命令,在本例中是注释的结尾
s/<pattern>//g
- 用空字符串替换每行出现的所有模式
我只想删除注释中的 "go"s,在 vi 或 vim 中。可以告诉我怎么做吗?
/*
the following gos should be deleted: in the comment
go
*/
the following go should not be deleted
go
/*
the following go should be deleted: in the comment
go
and some more words
go
*/
the following go should not be deleted
go
删除后的结果应该是这样的:
/*
the following gos should be deleted: in the comment
*/
the following go should not be deleted
go
/*
the following go should be deleted: in the comment
and some more words
*/
the following go should not be deleted
go
谢谢。
此行适用于您的示例:
%s#/\*\zs\_.\{-}\ze\*/#\=substitute(submatch(0),'go','','g')#
您可能想在 vim 的帮助文档中查看一些项目:
:h \zs
:h \ze
:h \_.
:h /star
:h :s\=
:h substitute(
你可以试试这个:
g/\/\*/.,/\*\//s/\<go\>//g
g/<pattern>/
- 匹配包含给定模式的行,在本例中是注释的开头.,/<patter>/
- 从当前行到匹配模式的下一行执行以下 ex 命令,在本例中是注释的结尾s/<pattern>//g
- 用空字符串替换每行出现的所有模式