如何在每行中替换除第一个以外的所有出现 - VIM

5

我有这样的数据:

母音,vowel    
備考,note, remarks, NB    
基本形,,fundamental form, basic form, basic pattern, basic model, basic type, prototype    
受身,,the defensive, passive attitude, passivity, passiveness, the passive, passive voice, ukemi (the art of falling safely)  
受身形,passive voice, passive form 
否定,negation, denial, repudiation, NOT operation 
不規則,irregularity, unsteadiness, disorderly  

如何替换每行除第一个以外的所有出现次数?

我想要在每行中替换除第一个逗号以外的所有逗号。

结果:

母音,vowel    
備考,noteREPLACED remarksREPLACED NB  
基本形,REPLACEDfundamental formREPLACED basic formREPLACED basic patternREPLACED basic modelREPLACED basic typeREPLACED prototype  
受身,REPLACEDthe defensiveREPLACED passive attitudeREPLACED passivityREPLACED passivenessREPLACED the passiveREPLACED passive voiceREPLACED ukemi (the art of falling safely) 
受身形,passive voiceREPLACED passive form  
否定,negationREPLACED denialREPLACED repudiationREPLACED NOT operation    
不規則,irregularityREPLACED unsteadinessREPLACED disorderly    
2个回答

4
你可以使用正向后顾(positive lookbehind)来解决此问题:
:%s/\m\%(,.*\)\@<=,/REPLACED/g

上帝保佑你,我的救星。真的非常感谢你的帮助。 - whitesiroi

0

由于每行逗号后面除了第一个都有空格,所以您可以采用以下方法。

%s/, /REPLACED /g
%s/,\+/,/g

第二个命令处理多个连续逗号,例如在第三行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接