I have a long line of words, looking like this:
foo,foo bar,bar@foo,foo# bar,bar$ foo#
Now I would like to turn it into:
"foo","foo bar","bar@foo","foo# bar","bar$ foo#"
Thus, the delimiter is a comma.
What is the best way to do this in vi(m)?
EDIT: Would anyone care to elaborate on the downvotes?
This seems to work. Capture everything thats not a comma and replace it with the captured part in quotes. The g at the end of the command says replace all instances that match the regex on the line. Without the g it would only match the first one. Take a look at :h :s and:h :s_flags
:%s/\([^,]\+\)/"\1"/g
Input:
foo,foo bar,bar@foo,foo# bar,bar$ foo#
Output:
"foo","foo bar","bar@foo","foo# bar","bar$ foo#"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With