Ad blocker interference detected!
Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers
Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.
created 2002 · complexity intermediate · author Larry Clapp · version 5.7
On line 300 of a thousand line file, Vim will show you that you're 30% through the file. But what if most of the lines have one character in them, and some of them have twenty thousand? Sometimes it comes in handy to know your percentage through the file in terms of current-byte / total-bytes. I looked through the Vim docs and couldn't find a way to do this, so I wrote a Vim function to show it.
Put this in your vimrc
function! Percent() let byte = line2byte( line( "." ) ) + col( "." ) - 1 let size = (line2byte( line( "$" ) + 1 ) - 1) " return byte . " " . size . " " . (byte * 100) / size return (byte * 100) / size endfunction
Uncomment the first return to see intermediate values.
And put this somewhere in your "set statusline=...":
Here is a variation on the same theme.
Add this to your vimrc, then type
:HF to display "Byte aaaa of bbbbb (xx%)" on the bottom line. Note: The command! statement is one long line.
function! BytePercent() let CurByte = line2byte (line ( "." ) ) + col ( "." ) - 1 let TotBytes = line2byte( line( "$" ) + 1) - 1 return ( CurByte * 100 ) / TotBytes endfunction command! -nargs=0 -bar HowFar echo "Byte " . ( line2byte( line( "." ) ) + col( "." ) - 1 ) . " of " . ( line2byte( line( "$" ) + 1 ) - 1 ) . " (" . BytePercent() . "%)" cnoreabbrev HF HowFar