To get this to work you have to know how many lines per page :hardcopy is normally making. Open empty document and in Normal mode "100o". Then make ":%s/^/\=line('.')". Now ":hardcopy > nu.ps". Open nu.ps in PostScript viewer. You will see how many lines per page Vim is printing.
+
To get this to work you have to know how many lines per page :hardcopy is normally making. Open empty document and in Normal mode "100o". Then make ":%s/^/\=line('.')". Now ":hardcopy > nu.ps". Open nu.ps in PostScript viewer. You will see how many lines per page Vim is printing.
In my case this is 73. Now set the 'printheader' option:
In my case this is 73. Now set the 'printheader' option:
Clever; however there are multiple settings (see e.g. 'printfont' & 'printoptions') which can change the number of lines per page. Also, if long lines wrap when printed (the default), then the number of lines in the buffer may not match the number of lines printed.
+
Clever; however there are multiple settings (see e.g. 'printfont' & 'printoptions') which can change the number of lines per page. Also, if long lines wrap when printed (the default), then the number of lines in the buffer may not match the number of lines printed.
----
----
A simpler way to do the page count arithmetic:
A simpler way to do the page count arithmetic:
−
:set printheader=%<%f%h%m=Page\ %N\ of %{(line('$')+72)/73}
+
:set printheader=%<%f%h%m=Page\ %N\ of %{(line('$')+72)/73}
Latest revision as of 08:53, September 29, 2008
Please review this tip:
This tip was imported from vim.org and needs general review.
created August 18, 2003 · complexity intermediate · author Mikolaj Machowski · version 6.0
To get this to work you have to know how many lines per page :hardcopy is normally making. Open empty document and in Normal mode "100o". Then make ":%s/^/\=line('.')". Now ":hardcopy > nu.ps". Open nu.ps in PostScript viewer. You will see how many lines per page Vim is printing.
In my case this is 73. Now set the 'printheader' option:
I forgot about case when total number of lines is multiplication of lines per page. Here is an improved version. Number of lines per page was put in variable - you have to change it only once.
function! PH_Multiple()
let lpp = "73" " lpp - lines per page
let modulo = line('$') % lpp
if modulo != 0
return ( line('$') / lpp ) + 1
else
return line('$') / lpp
endif
endfunction
set printheader =%<%f%h%m%=Page\ %N\ of\ %{PH_Multiple()}
Clever; however there are multiple settings (see e.g. 'printfont' & 'printoptions') which can change the number of lines per page. Also, if long lines wrap when printed (the default), then the number of lines in the buffer may not match the number of lines printed.
A simpler way to do the page count arithmetic:
:set printheader=%<%f%h%m=Page\ %N\ of %{(line('$')+72)/73}