Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (46 sloc) 2.486 kB
57da1e4 @runpaint Add Printing recipe.
authored
1 <h3 id="printing">Printing</h3>
2
3 <h4>Problem</h4>
4
5 <p>You want to print something from Vim.</p>
6
7 <h4>Solution</h4>
8
9 <p>In GVim there's a <i>Print</i> entry on the <i>File</i> menu, and a printer
adcd504 @runpaint Tweak formatting.
authored
10 icon on the toolbar. In Vim execute <tt>:hardcopy</tt>.</p>
57da1e4 @runpaint Add Printing recipe.
authored
11
12 <h4>Discussion</h4>
13
14 <p><tt>:hardcopy</tt> converts the current file to Postscript and sends it to
15 the default printer. You can specify that a different printer is used with
16 <tt>:set
17 pdev=<var>printer</var></tt>. For example, <tt>:set pdev=usblp1</tt>.</p>
18
adcd504 @runpaint Tweak formatting.
authored
19 <p>If you have a <abbr title="Portable Document Format">PDF</abbr> printer
57da1e4 @runpaint Add Printing recipe.
authored
20 installed<span class="fn">Linux/Mac users can
adcd504 @runpaint Tweak formatting.
authored
21 install the <i>CUPS PDF</i> package to get a PDF printer, e.g. on
57da1e4 @runpaint Add Printing recipe.
authored
22 Debian/Ubuntu: <tt>apt-get install cups-pdf</tt>.</span>, you can use this
23 technique to print a file to PDF. For example, assuming your PDF printer is
24 called <tt>pdf</tt>:</p>
25
26 <pre><code>set pdev=pdf
27 set printoptions=paper:A4,syntax:y,wrap:y</code></pre>
28
29 <p>The <tt>printoptions</tt> line is a comma separated list of values that
30 affect how Vim formats the document before it sends it to the printer. A list
31 of options is at <tt>:help popt</tt>.</p>
32
33 <p>The <tt>paper</tt> option sets the paper size. It accepts values such as
34 <tt>A3</tt>, <tt>letter</tt>, and <tt>legal</tt>.</p>
35
36 <p>The <tt>syntax</tt> option determines whether the document is printed with syntax
37 highlighting. By default it has the value <tt>a</tt> which means that Vim only
38 uses highlighting for colour printers. A value of <tt>y</tt> forces
39 highlighting.</p>
40
41 <p>Lines are wrapped when <tt>wrap:y</tt>, which is the default. If
42 <tt>wrap</tt> has the value <tt>n</tt>, long lines are truncated.</p>
43
44 <p>Other useful options are <tt>header:0</tt> to stop a header from being
45 printed, <tt>number:y</tt> to number lines, <tt>duplex:off</tt> to print on
46 only one side of the page.</p>
47
48 <p>On Linux the <tt>lpr</tt> utility is used for printing. To use a different
49 program add a stanza such as the following to your <a
50 href="#configuring-vim"><tt>vimrc</tt></a>:</p>
51
52 <pre><code>set printexpr=PrintFile(v:fname_in)
53 function PrintFile(fname)
54 call system("a2ps " . a:fname)
55 call delete(a:fname)
56 return v:shell_error
57 endfunc</code></pre>
58
59 <p>The above example specifies that the GNU <i>Anything to Postscript</i>
60 (<tt>a2ps</tt>) utility is used for printing. <tt>a2ps</tt> can print two
61 pages per physical page and custom headers, for example; see <tt>man a2ps</tt>
62 for a complete list of features.</p>
Something went wrong with that request. Please try again.