Is there a solution to printing unicode characters from gvim
?
See this:
Results in this print result
(Using a Linux setup and Vim 8.0.)
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityPer this Stackoverflow:4586628 Q/A, How do you pipe a vim buffer through lpr?, I have this entry in my ~/.vimrc
:
nmap PpP :%w !lpr -o lpi=8 -o cpi=14<CR><CR>
that replaces my old entry,
nmap PpP :ha<CR>
(:ha
= :hardcopy
).
Using :ha
, Neovim was not printing Greek letters, ... even though my (Arch Linux) locale
was
LANG=en_US.UTF-8
...
and I have this line, near the top of my ~/.vimrc
,
scriptencoding utf-8
[Printing is system-dependent, not vim-dependent.]
I added the lpi
(lines-per-inch) and cpi
(characters-per-inch) to jiggle my font size to that similar to as what I was getting with the :ha
command (I measured/counted with an actual ruler), and run it as a PpP
command/shortcut, added to my ~/.vimrc
, whenever I want to print the current buffer.
Send the buffer to the browser by converting to HTML, then print from there:
:TOhtml | w | !open -a Safari %
For example I have this in vim:
If I type
:ha
But when I send it to the browser I get this (with color scheme!):
I have this in my .vimrc, which deletes the new html buffer and stored file:
nnoremap <F2> <ESC> :TOhtml <bar> w <bar> !open -a Safari % <CR> <bar> ZQ <CR> <bar> execute '!rm %:p.html' <CR>
Vim seems to produce fairly simple PostScript through the :hardcopy
command. PostScript itself has no understanding of Unicode, and so having it render "special characters" properly is a complicated process involving intimate knowledge of fonts, etc.
I filed a bug about this, FWIW: https://github.com/vim/vim/issues/8935
I the meantime, I think the best solution is to use an external program to produce your printable output. For instance paps
(link) converts UTF-8 text to PostScript. You can, of course, run this external program from inside Vim using your own command, as described in another answer.
:set enc? fenc? penc?
(as one command)encoding=utf-8
fileencoding=
printencoding=
set penc=utf8
the problem in the printed output persists.