using this file (inside, not the zip):
https://github.com/vim/vim/files/13720982/index_video_5_0_1.zip
If I open the same file in GVIM and enter /mdat
, enter
, g
, ctrl+g
I get:
Byte 2785
if I run this Go program:
package main import ( "bytes" "os" ) func main() { b, err := os.ReadFile("index_video_5_0_1.mp4") if err != nil { panic(err) } i := bytes.Index(b, []byte("mdat")) println(i) }
I get 2578. why is Vim off by over 200 bytes?
https://github.com/vim/vim-win32-installer/releases/tag/v9.0.2175
https://github.com/vim/vim-win32-installer/releases/tag/v9.0.2175
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
You need to edit the file with vim -b
or :edit ++bin
, otherwise Vim will convert the file encoding and the line endings.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
if I use your option I get 2579, which is OK since Vim starts with 1. thank you!
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Closed #13731 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Reopened #13731.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
I think I agree with the previous user. the byte offset is 2578 (or 2579 in VIM), so its should not be possible for VIM to be returning any higher number such as 2785. so I would consider that an error. the byte is the smallest "unit of measurement", so it should always be the highest quantity. reopening this.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
As I said in the previous comment, if 'binary' is not set, Vim converts the line endings of a file to be LF, CR or CRLF.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
that doesnt explain the increased count. can you please clarify?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
And, some bytes in the file correspond to a multibyte char in latin-1 encoding, so such a byte counts as two bytes.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
Closed #13731 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
To be clearer, in Vim, 'encoding' is set to utf-8
by default, while the file is recognized as a latin1
file. g_CTRL-G
returns the byte count in Vim's current 'encoding', and some bytes in the file correspond to a single-byte char in Latin-1, but a multi-byte char in UTF-8.
Therefore, this will also not happen if you run Vim with --cmd 'set encoding=latin1'
.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.