No edit summary |
(Remove html character entities) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{review}} |
{{review}} |
||
+ | {{TipImported |
||
− | {{Tip |
||
|id=533 |
|id=533 |
||
+ | |previous=531 |
||
− | |title=Page 1 of 123 in header of |
||
+ | |next=534 |
||
− | |created=August 18, 2003 |
+ | |created=August 18, 2003 |
|complexity=intermediate |
|complexity=intermediate |
||
|author=Mikolaj Machowski |
|author=Mikolaj Machowski |
||
|version=6.0 |
|version=6.0 |
||
|rating=18/9 |
|rating=18/9 |
||
+ | |category1= |
||
− | |text= |
||
+ | |category2= |
||
− | To get this to work you have to know how many lines per page :hardcopy |
||
⚫ | |||
+ | 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. |
||
⚫ | |||
− | is normally making. Open empty document and in Normal mode "100o". Then |
||
⚫ | |||
− | make ":%s/^/\=line('.')". Now ":hardcopy > nu.ps". Open nu.ps in |
||
+ | <pre> |
||
− | PostScript viewer. You will see how many lines per page Vim is printing. |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | </pre> |
||
+ | ==References== |
||
+ | *{{help|'statusline'}} |
||
⚫ | |||
+ | 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. |
||
+ | <pre> |
||
− | In my case this is 73. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | else |
||
⚫ | |||
+ | endif |
||
⚫ | |||
⚫ | |||
+ | </pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | |||
− | |||
− | Explanations of % items in option are here |'statusline'|. |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | "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 :) |
||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | else |
||
⚫ | |||
− | endif |
||
⚫ | |||
⚫ | |||
− | |||
− | |||
− | Mikolaj |
||
− | , August 19, 2003 4:36 |
||
---- |
---- |
||
⚫ | |||
⚫ | |||
− | Peppe Guldberg: |
||
− | |||
⚫ | |||
− | |||
− | NOTE: smart use of condition |
||
− | |||
− | Anthony: |
||
− | |||
⚫ | |||
− | |||
− | IMO this is best of all: oneliner and number of lines appears only once - easy to correct. |
||
− | |||
− | Thanks! |
||
− | |||
− | Mikolaj |
||
− | , August 20, 2003 8:20 |
||
---- |
---- |
||
+ | A simpler way to do the page count arithmetic: |
||
⚫ | |||
+ | :set printheader=%<%f%h%m=Page\ %N\ of %{(line('$')+72)/73} |
||
− | Given these limitations, it would be great if the 'printheader' header option was extended (Vim 7?) to handle this in the Vim code itself. Maybe %T = Total number of pages to be printed. |
||
− | |||
− | |||
− | '''Anonymous''' |
||
− | , November 22, 2004 4:57 |
||
⚫ | |||
− | <!-- parsed by vimtips.py in 0.532027 seconds--> |
Latest revision as of 08:53, 29 September 2008
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:
:set printheader=%<%f%h%m%=Page\ %N\ of\ %{line('$')/73+1}
line('$') - number of lines in buffer 73 - number of lines per page +1 - Vim uses integer math and everything rounds down.
References[]
Comments[]
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()}
Some nice additions from comp.editors:
:set printheader=%<%f%h%m%=Page\ %N\ of\ %{line('$')/73+(line('$')%73!=0)}
:set printheader=%<%f%h%m%=Page\ %N\ of\ %{(line('$')-1)/73+1}
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}