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.)
Not trivially, but as a workaround, you can convert to HTML then print that from a browser. For example, on a Debian/Ubuntu-based Linux distro:
:TOhtml | w | !x-www-browser %
This might work for other distros:
:TOhtml | w | !xdg-open %
This should work on macOS:
: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>
set background=dark
in your .vimrc
, you might want to :colorscheme default
(twice) to ensure that what you see on the screen better matches what comes out of the printer. Otherwise you're likely to end up with something like yellow (basically invisible) line numbers in your printout.
Per 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.
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.