I'm not sure that libraries exist to do this in pure vimscript, however, vim does allow you to embed Python, and Python has BeautifulSoup which can handle converting html entities to unicode:
I don't have python support enabled on my vim, so I had to settle for writing an external script, soup.py
, which converts html entities to UTF-8:
# soup.py
from BeautifulSoup import BeautifulStoneSoup
import sys
input = sys.stdin.read()
output = str(BeautifulStoneSoup(input, convertEntities=BeautifulStoneSoup.HTML_ENTITIES))
sys.stdout.write(output)
(FYI, I don't know python, so even though that works, it's probably pretty ugly)
You can use it in vim by selecting the lines with entities
you want to convert in visual mode, and passing them to the script thusly:
:'<,'>!python soup.py
For example, if my cursor was on a line reading
∴ i ≠ 10
And I hit
!!python soup.py<Enter>
It would convert it to
∴ i ≠ 10