Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim 使用vi替换包含某些字符的行_Vim_Vi - Fatal编程技术网

Vim 使用vi替换包含某些字符的行

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

我想将所有包含“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,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"