Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I separate pages with Vim?

Tags:

vim

I have the requirement of separating an ASCII document into pages of max length 58 lines per page. At the bottom of each page there is a 3 line footer. I'm not aware of any pagination abilities within Vim that would accomplish this.

Is there a good way to do this with Vim? Perhaps highlighting every 58th line or something of the sort.

N.B. I'm seeing answers involving using a separate tool to do this; which I have thought of. What I'm interested in is a Vim solution.

Thanks.

like image 887
Pierre-Antoine LaFayette Avatar asked Feb 01 '26 00:02

Pierre-Antoine LaFayette


2 Answers

The proper tool you're looking for is very likely a2ps.

a2ps --lines-per-page 58 --footer=footer_text document.txt
like image 85
MikeyB Avatar answered Feb 02 '26 17:02

MikeyB


It's possible in vim as a script. Put the following in a file and :source it while the file to change is open. The s:footer list are the lines to insert after each run of 58 lines.

let s:footer = ["","Footer",""]
let s:line = 0

while s:line <= line("$") - 58
  let s:line = s:line + 58
  call append(s:line, s:footer)
  let s:line = s:line + len(s:footer)
endwhile
like image 24
Geoff Reedy Avatar answered Feb 02 '26 18:02

Geoff Reedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!