4

I've discovered the :hardcopy command, which is the equivalent of the Command-P command in MacVim.

I've also found that it accepts ranges. For instance, in my markdown file, I can split the sections into multiple PDFs like so:

:1,1/^#.* 4 /-ha | 1//,/^#.* 6 /-ha | 1//,/^#.* 7 /-ha | 1//,/^#.* 8 /-ha | 1//,/^#.* 9 /-ha | 1//,$ha

(My section headers look like: # Exercise 1 - (Name of exercise), etc.)

This command prints sections 1-3 into one file, sections 4-5 into the next, sections 6, 7, and 8 each in separate files, and from section 9 to the end of the file into another file.

However, with the default print header this results in all of these files starting with "Page 1". I can suppress that header and print only the filename by running:

:set pheader=%f

but ideally, I'd like to have all of these exercises in the same PDF, with proper page numbers in the header, and with the exercises each cleanly on their own page (and some short exercises printed together on the same page as per the printing command above).

I further found that with :set popt=paper:letter (letter size PDF printouts), and no other settings modified from my system defaults, a single page of printout contains 69 lines of text, wrapped after 86 columns. (So a line longer than 86 columns counts extra toward the 69 line per page limit.)

I found that I can achieve what I want (exercises cleanly separated onto separate pages of the printout) by just inserting extra empty lines into the document so that the intended page breaks line up every 69 lines, being sure to compensate for any overly long lines. However, this is really inconvenient when making edits up and down the document; I would have to keep fussing with the padding lines to ensure the printout stayed true.

How can I force page breaks to occur in the MacVim printed output in specified locations?

6

From :help popt-option:

formfeed:y  When a form feed character is encountered, continue
            printing of the current line at the beginning of the
            first line on a new page.

So…

  1. add the line below to your vimrc:

    set printoptions+=formfeed:y
    
  2. insert a form feed where you want your page break to occur with <C-l> in insert mode,

  3. do :hardcopy.

  • Awesome! That's perfect! So then for my use case, I guess that character should be right before the # at the start of the header lines...any idea if that will screw up markdown renderers? – Wildcard Mar 15 '16 at 13:15
  • It does screw up the rendering, but by putting it on its own line just before, all is well. Except it takes up extra page real estate, but oh well. – Wildcard Mar 15 '16 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.