0

I have the following text:

," abc def , qwerty ghans , ghjt bnsn 5667w !*? ",

I want to match and substitute the commas in between ," AND ", for another character (or better yet, remove them).

FG74
  • 61
  • 1
  • 6
  • `:%s/\("\)\@<!,\("\)\@!/#/g` – Meninx - メネンックス Dec 29 '16 at 17:28
  • 1
    Stack Overflow is not about others doing the work for you. What have you tried, where are you struggling? – mMontu Dec 29 '16 at 18:55
  • 1
    What gives you the idea that i would through the trouble of posting a question without trying hard first? I have tried a lot of things and have gotten nowhere. No point in posting all of them here. It would make the question hard to read. If you find this question "lazy", please, just ignore it. – FG74 Dec 30 '16 at 19:03
  • I'm guessing you need a more general solution to apply to other similar situations as well but, in this specific case you could just use `:%s/ , / /g` – Steve Occhipinti Jan 02 '17 at 22:01

2 Answers2

1

A nice way in my opinion is using substitute in Visual mode.

start visual(using v) on ,", search for the ending characters using /", in order to select all the characters within the pattern, and than, when you press : in order to write a command, the following will show: :'<,'>, which means the command will be applied on the selected zone. finally, :'<,'>s/,//g will do.

user3848844
  • 509
  • 6
  • 20
1

Plugin solution

My PatternsOnText plugin provides (among others) a :SubstituteInSearch command. For your example, I'd select the text (non-greedily) via ,"\zs.\{-}\ze", and then run the substitution on it:

:SubstituteInSearch/,"\zs.\{-}\ze",/,/X/g

Built-in alternative

If there are few occurrences, you can get by with selecting the area, and then (and this critical part is missing from @user2848844's related answer!) restricting the matching via the special \%V atom:

'<,'>s/\%V,/X/g
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324