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
VIM代用品首次出现_Vim_Format_Substitution - Fatal编程技术网

VIM代用品首次出现

VIM代用品首次出现,vim,format,substitution,Vim,Format,Substitution,我有一个文本文件,其中包含以下格式的行: some text:23: class Headphones : Device { // comment this is a comment 我要做的是将第一次出现的:stuff:替换为:stuff:,(之后添加一个额外的逗号) 这条线将变成: some text:23:, class Headphones : Device { // comment this is a comment 我尝试的是%s/:*:/&/,但是搜索匹配的是:23:class

我有一个文本文件,其中包含以下格式的行:

some text:23: class Headphones : Device { // comment this is a comment
我要做的是将第一次出现的
:stuff:
替换为
:stuff:,
(之后添加一个额外的逗号) 这条线将变成:

some text:23:, class Headphones : Device { // comment this is a comment

我尝试的是
%s/:*:/&/
,但是搜索匹配的是
:23:class耳机:
,而不是第一次出现。。。发生了什么?我如何才能实现我想要的?

您需要使用
\{-}
使您的匹配不贪婪:

%s/:.\{-}:/&,/

您可以删除后面的引用,只需使用
&
进行匹配。因此,缩短的替换将是
:%s/:.\{-}://&,
@FDinoff:谢谢!更新。