Thanks to @BobHyam's question and to @BenjiFischer's answer on the list [email protected], I found out how to print to hardcopy while integrating form feeds:

  • in ~/.vimrc

    "   ^L
  • by analogy, in foo.sh

    #   ^L

followed by something like:

:set popt+=formfeed;y,left:15mm,right:15mm

With that in mind, and knowing that converting vim generated text into an html file is also possible with:


... I could not find a solution on how to insert arbitrarily placed html page breaks in the yet to be converted vim file (the code) so it would mess up neither the code nor the document converted to html.

Has anybody ideas on whether it can be done (with a reasonable effort) prior or upon conversion to html, from the vim buffer ?

Note: I am not asking about html syntax. I do know how to insert a page break in html while writing html. That bit is off topic here. What I am after is a way to code using vim and prior to converting all or part of a buffer to an html document, to introduce from vim the necessary html page breaks, without disrupting the code.

  • @muru: why the edit with a backslash before the # sign in \# ^L for a shell script ? Tx.
    – Cbhihe
    Sep 16, 2015 at 7:59
  • The backslash was already there. All I did was add code formatting, so that the characters you want to show are shown exactly as given.
    – muru
    Sep 16, 2015 at 11:45
  • @muru: Weird, it did not show in my original rendering, Tx and fixed.
    – Cbhihe
    Sep 16, 2015 at 12:51

1 Answer 1


$VIMSCRIPT/syntax/2html.vim is the file responsible with html generation. Apparently, the \x0c character (inserted in Vim with Ctrl-V Ctrl-L) will never be found and replaced by Vim, since the strtrans() function already replaced its occurences with the literal 2-letter sequence ^L.

The easiest way IMHO would be to simply place special comment lines in Vim (you could keep " ^L for compatibility with hardcopy), run :TOhtml and then, in the html output buffer, run a substitute command:

:%s/^.*&quot;\s*^L.*/<p="page-break-before: always">/

... then save your html output buffer. This changes the whole line that contains a start-Vim-comment char followed by any number of whitespaces and a ^L sequence or char. The replacement part can be anything you want - I have no idea about which html tags are used to break pages - but you say you have no problems with that.

If/when all works well, you can make a command that calls both of the above in sequence, and map it to a key combo.

  • Thanks ! Yr doc wide substitution cmd :%s/.../.../ looks good especially because as you point out I can always retain the # ^L in the original code for :hardcopy compatibility. I don't think the html snippet included as substitute would work though. Better to define a new class up in the HEAD section of the html doc and invoke it whenever you break pages. -- I was looking for something probably not doable, i.e. to introduce an html snippet from the original vim buffer prior to running syntax/2html.vim, not in the new buffer containing the html code. No automation here unfortunately.
    – Cbhihe
    Sep 17, 2015 at 20:07
  • Indeed - although using the above model you could place "special html snippets" between some markers in Vim comments and look for them afterwards in the html buffer, in order to replace the whole line with one of those special html snippets. E.g. from " *<p>* to <p>, using a substitution such as: :%s/^.*"\s*\*\(.*\)\*.*/\1/ (not tested).
    – VanLaser
    Sep 17, 2015 at 21:39
  • Yes, possible, but why further complicate one's life ? Better yet stick with :%s/^.*&quot;\s*^L.*/<P CLASS="pgbrk">/ or :%s/^.*#\s*^L.*/<P CLASS="pgbrk">/ and write a post processing function in ~/.vimrc or as a script: (i) to insert a new class P.pgbrk definition at an appropriate location between <HEAD> and </HEAD> and (ii) to perform the above substitution, all in the emergent html buffer, i.e. after running syntax/2html.vim.
    – Cbhihe
    Sep 18, 2015 at 12:50
  • Yes - I was thinking of a general solution, in which you insert - in Vim comments - any html patterns which you want to replace those entire comment lines with, in html - then use a single, generic substitute command after TOhtml that deals with all of them at once.
    – VanLaser
    Sep 18, 2015 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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