We may earn money or products from the companies mentioned in this post.
Thank you for helping to support my work!

Sometimes I get these Word docs that need to be used in WordPress or PHPlist. Sending out mass attachments is a huge no-no so I needed a way to quickly clean these things up in vim. I’m sure there are other tools out there that could do this in one or two clicks but vim is now a major part of my workflow.

:set fileencoding=utf-8
" Leave Latin-1 behind, set to UTF-8

:%s/[\u0026]\{1}/\&/g
" Convert ampersands

:%s/[\u2026]\{1}/\…/g
" Convert elipses

:%s/[\u201C]/\“/g
" Convert double quotes, left

:%s/[\u201D]/\”/g
" Convert double quotes, right

:%s/[\u2018]/\‘/g
" Convert single quotes, left

:%s/[\u2019]/\’/g
" Convert single quotes, right

:%s/[\u2013]/\–/g
" Convert N Dashes

:%s/--/\–/g
" Convert double dashes to N Dashes

:%s/.  /. /g
" Remove double spaces after periods

:%s/.   /. /g
" Remove triple spaces after periods

:%s/.[\uA0]\{2}/./g
" Remove double non-breaking spaces after periods

:%s/.[\uA0]\{1}/./g
" Remove single non-breaking spaces after periods