In order to overcome my irritation with quoting and comma separating words in a list, I thought I would play with Vim's search and replace to allow myself to type lists like this:daqs = [this is a test of some cool vim stuff for creating a comma separated list of strings]and use a regular expression to convert this line to this:daqs = [this, is, a, test, of, some, cool, vim, stuff, for, creating, a, comma, separated, list, of, strings, ]I visually selected everything inside the brackets, and used the expression::'<,'>s/\%V\S\+[^\]]/\&\, /gBut a trailing whitespace character seems to be following my & insertion, giving me this:daqs = [this , is , a , test , of , some , cool , vim , stuff , for , creating , a , comma , separated , list , of , strings, ]Note that the final word does not have a space at the end within the quotes. How can I match each word between the brackets without carrying around this ending whitespace?
Extra trailing whitespace in regex match using &
regular expression;search
I made it work with a different regex::'<,'>s/\%V[^] ]\+/\&\,/gdecomposing::'<,'>s/        start a new substitution command\%V             match inside the visual selection[^] ]\+         match everything but a space and a closing ] (1 or more time)/               replace with\&\,          the quoted matched group followed by a space and a ,/g              replace globally