I have lines like the following ones (actually function prototypes)void ()word ( word, another word, one_more word, ..., hello, ... )one argument ( only )I want to match each single argument and enclose it between < and >.Before wasting time with the replacement string, I'm trying to devise the proper search pattern. The following command:%s/\(( \|, \)\(.\{-}\)\( )\|,\)/\1<\2>\3/gonly matches and replace odd-position arguments.
Substitute words enclosed between comma or open-parenthesis and comma or closed parenthesis
regular expression;substitute;delimiter matching
It's because your matching groups have overlap! Exept for zero-width pattern items, every charachter in your string will be consumed in the matching. so here you can use \zs and \ze to confine your match::%s/\%(( \|, \)\zs\(.\{-}\)\ze\%( )\|,\)/<\1>/gHere i also changed the first and third captuting groups to non-capturing as we don't need to capture them.for a complete list of zero-width pattern items, see: :h pattern-overview