Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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    
like image 751
whitesiroi Avatar asked Sep 26 '22 22:09

whitesiroi


1 Answers

You can use positive lookbehind for this:

:%s/\m\%(,.*\)\@<=,/REPLACED/g
like image 90
Sato Katsura Avatar answered Oct 12 '22 10:10

Sato Katsura