Vim 使用vi替换包含某些字符的行
我想将所有包含“CreateTime=xxxxx”的行替换为“CreateTime=2012-01-04 00:00”。我可以知道我该如何使用vim吗Vim 使用vi替换包含某些字符的行,vim,vi,Vim,Vi,我想将所有包含“CreateTime=xxxxx”的行替换为“CreateTime=2012-01-04 00:00”。我可以知道我该如何使用vim吗 [m18] Attendees=38230,92242,97553 Duration=2 CreateTime=2012-01-09 22:00 [m20] Attendees=52000,50521,34025 Duration=2 CreateTime=2012-01-09 00:00 [m22] Attendees=95892,2368
[m18]
Attendees=38230,92242,97553
Duration=2
CreateTime=2012-01-09 22:00
[m20]
Attendees=52000,50521,34025
Duration=2
CreateTime=2012-01-09 00:00
[m22]
Attendees=95892,23689
Duration=2
CreateTime=2012-01-08 17:00
您可以使用全局替换运算符
:%s/CreateTime=.*$/CreateTime=2012-01-04 00:00/g
您可以使用以下工具从Vim中读取s
命令的帮助:
:help :s
您可以使用:help pattern overview
阅读有关模式的信息
根据要求,进一步介绍正则表达式匹配(CreateTime=.*$
):
总之,它与
CreateTime=
匹配,后跟任何一系列字符,占用了行的其余部分。可能重复的字符。请解释一下这部分:.*$@SagarJain I编辑了答案,并提供了更多信息。
CreateTime= # this part is just a string
. # "." matches any character
* # "*" modifies the "." to mean "0 or more" of any character
$ # "$" means "end of line"