vim - How do I merge these two regexs into a single one? -


i'm using 1 remove whitespace:

%s/\s\+//g 

and 1 wrap comma-separated words between double quotes (and leave 1 space after comma):

%s/\s*\([^,]\+\)/ "\1"/g 

i tried merging them this:

%s/\s\+//\|/\s*\([^,]\+\)/ "\1"/g 

but trailing characters error.

how correctly merge 2 regexs?

because replacement part different, you'd have use :help sub-replace-expression differentiate between 2 regexp parts , either remove or double-quote, this:

:%s/\s\+\|\s*\([^,]\+\)/\=empty(submatch(1)) ? '' : ' "'.submatch(1).'"'/g 

but still doesn't make sense, because deletion of trailing whitespace come after it's been double-quoted. these 2 substitutions aren't related, should concatenate 2 commands | command separator (in mapping, you'd use <bar> instead):

:%s/\s\+//g|%s/\s*\([^,]\+\)/ "\1"/g 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -