Convert Excel TSV to CSV in vim

After Copy-Paste some data from MS Excel spreadsheet, it appeared to be half thousand TSV (Tab Separated Values) lines in vim. Then it took around 20 seconds to convert it to CSV! So, how did I do it so quickly?

Okay, it was just two simple replace command using vim regexp –

:%s/\t\(.*,[^\t]*\)\t/\t"\1"\t/g 
:%s/\t/,/g

The first line is adding quotes around column values which have comma in it. And the next one is to replace tabs with comma. Done!

Hope this tip will save someone’s time someday 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *