Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode printing in vim

I am working with text files that contain a lot of unicode characters (≼, ⊓, ⊔, ...). Vim displays them fine, but when I print they are replaced by a generic character. Gedit prints them without problem, but it's a bit of a pain to launch another editor just to print.

Is there a way to get vim (on Linux/Gnome) to print properly? I tried using vim-gnome, in hope that it would use the same infrastructure as gedit, but it does not.

like image 234
mdgeorge Avatar asked Aug 14 '12 14:08

mdgeorge


2 Answers

Vim is only able to use 8-bit encoding for printing. If there is encoding that includes all those characters all you need is to use

set printencoding={encoding}

If there is not then you can’t print it from vim directly. You can use :TOhtml command suggested by @DaoWen, do

:TOhtml
:w /tmp/print.html
:!command-that-makes-browser-print-a-file(I-do-not-know-one) /tmp/print.html
:!rm /tmp/print.html

. You can also use my formatvim plugin to print this to pdf through latex (don’t forget to file bug reports: latex-xcolor output is untested):

:Format format latex-xcolor to /tmp/print.tex
:!pdflatex /tmp/print.tex && lp /tmp/print.pdf && rm /tmp/print.*

(you can use html output as well, but that will not make me know a command to print it). Of course, you can map these to a single key.

like image 70
ZyX Avatar answered Nov 07 '22 22:11

ZyX


Try using the :TOhtml command to convert your document to output your buffer in HTML format. You should be able to print the resulting file from your browser.

like image 37
DaoWen Avatar answered Nov 07 '22 20:11

DaoWen