简体   繁体   中英

How to replace every occurrences except the first one on every line - VIM

I have data that looks like this:

母音,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  

How to replace every occurrences except the first one on every line?

I want to replace every , on every line except the first occurrence of , on every line.

Result:

母音,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    

你可以使用正面的lookbehind:

:%s/\m\%(,.*\)\@<=,/REPLACED/g

Since there is a space character after each comma except the first on each line you could do the following.

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

The second command takes care of multiple consecutive commas, like on the third line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM