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?