Tip #268: Get cursor position as byte percentage instead of line percentage
tip karma |
Rating 5/9, Viewed by 402
|
created: |
|
June 27, 2002 7:16 |
|
complexity: |
|
intermediate |
author: |
|
Larry Clapp |
|
as of Vim: |
|
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=...":
%{Percent()}%%
See "help statusline", "help eval".
<<selectively displaying abbreviations |
Syntax highlighting is "out of sync", seems to correct itself with refresh ?? >>
Additional Notes
|