Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get printer dialog in GVim on Linux?

Sometimes I like to print some code to understand it. Clicking on the Print button in GVim on Linux prints to the default printer with some default settings.

How can I get the standard printer dialog when I want to print from GVim?

This is so that I can choose a printer (from multiple printers available on the work network) and change other print settings (duplex, pages per side, etc).

like image 669
Ashwin Nanjappa Avatar asked Oct 09 '14 14:10

Ashwin Nanjappa


2 Answers

See :h hardcopy and :h print-options.

You can set the set the printer using :set printdevice=xxx and other options using :set printoptions=xxx.

If you really want to use the dialog box you could print to a file then open that file from some other program to print it :hardcopy > output.ps

like image 160
Brett Y Avatar answered Nov 15 '22 13:11

Brett Y


To obtain a print dialog upon printing in gvim, you can add the following to ~/.vimrc:

set printexpr=PrintFile(v:fname_in)
function PrintFile(fname)
  call system("kprinter " . a:fname)
  call delete(a:fname)
  return v:shell_error
endfunc

Instead of kprinter, which is the print dialog from KDE3, you can also use gtklp or whatever is the the print dialog command of your desktop environment.

like image 43
LaTechneuse Avatar answered Nov 15 '22 15:11

LaTechneuse