I'm trying to understand how ID3 tags work, so, after reading some documentation, I started to look at some mp3's raw data. Vim is usually my editor of choice, so, after some googling, I found out I could use xxd to see an hex representation of my files by invoking
:%!xxd
Everything worked fine, but when I put everything back in order with
:%!xxd -r
and quit, I found out that the file was modified; vlc could no longer play it, and diff told me the files differed. I thought I modified something by accident, but further experiments showed me that even opening the file and using xxd and then xxd -r changes somehow the file.
Why is that? How can I prevent it from happening? Am I doing something wrong?
xxd is a linux command. Once the file is open, press ESC and then type :%! xxd -b and then press ENTER . Press ESC and then i for "INSERT" mode which allows you to edit.
When I saw Tim Pope's excellent vim-afterimage script, it reminded me that Vim is completely capable as a binary file editor. Opening a file with -b or running :set binary makes Vim more suitable for editing binary files: textwidth and wrapmargin are set to 0.
To open the Binary Editor on an existing file, go to menu File > Open > File, select the file you want to edit, then select the drop arrow next to the Open button, and choose Open With > Binary Editor.
Obviously if you do not intend to change anything to a file you could quit vim
using :q!
.
As @RunHolt points out, vim
and xxd
can change a binary file. e.g. changing LF to CRLF or appending an LF character at the end of file.
You can prevent this by setting the binary
option:
Either start vim
as: vim -b filename
or type :set binary
before loading the file into the buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With