views:

757

answers:

2
+9  A: 

You want what Vim calls “digraphs”: read :help digraphs to see how they're used, and :digraphs to list the defined ones in your Vim.

Summary: in insert mode, press ^K (which causes Vim to display a highlighted ?, waiting for further input), then the defined two characters of the digraph. Vim then replaces what you typed with the defined resulting character. E.g. ‘^K’, ‘!’, ‘=’ produces ‘≠’.

bignose
Awesome, that's a step in the right direction, now I just need to switch to Unicode so the digraphs exist for the Unicode math characters.
Fire Crow
+1  A: 

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

&there4; i &ne; 10

And I hit

!!python soup.py<Enter>

It would convert it to

∴ i ≠ 10
rampion