Vi(m) tip #6: save a file with digraphs as utf-8 plain text
Alec Jacobson
December 22, 2009
I took all of my algorithms notes this semester in vim using digraphs for math symbols. Today I wanted to cat
all the files and print the results. However, I had overlooked that when vim inserts a digraph it's subtly displaying a UTF-8 character in your terminal but not necessarily saving your file with this encoding. To be sure issue the following commands from command mode in vim:
:set enc=utf-8
:e
:wq
When I want to view or print my notes, I insert them into a <pre> tag in an html document, using my converter script to take care of escaping wakkas and being sure to declare utf-8 charset in the content-type meta attribute:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-type' content='text/html;charset=UTF-8' >
</head>
<body>
<pre>
Paste escaped UTF-8 plain text here
</pre>
</body>
</html>
My UTF-8 notes as a HTML page viewable in browser.
source