There is, of course, a pattern of length 0 that works in one pass, but since I have never had much success in using, I prefer this approach:
:%s/\%("[^"]*"\)*\("[^"]*"\)/\=substitute(submatch(1), ' ', '_', 'g')/g
Note: double quotes are kept grouped 2 by 2 so as not to convert
foo bar "foo bar" "foo barr"
in
foo bar "foo_bar"_"foo_barr"
EDIT: as indicated in the ramp, more than enough:
%s/"[^"]*"/\=substitute(submatch(0), ' ', '_', 'g')/g
Luc hermitte
source share