Edit binary file with vim using the xxd command
To check binary file content
xxd <file name>
To edit a binary file
- Open the binary file normally with vim
vim <file name>
- Convert them to xxd human-readable format
- Edit the hex part in the left
- Convert xxd human-readable format back to binary
- Save modified content
Here are some useful vim commands to work with binary file
ga: print ASCII value of the character under the cursor
g8: print the utf-8 encoded binary of the character being displayed under the cursor, regardless of the value of
8g8: find the first invalid utf8 byte sequence.
- To prevent vim from appending a newline character
a0at the end of file
:set binary, then
- To open a file in binary format, without de-coding its content. In other words, utf-8 compatible characters are shown as human-readable while illegal characters are shown as hex value
:set binary then
:e (you must re-open the buffer)
vim -b <file name>
Sematic binary format read/write.
fq is a handy binary inspector/decoder written in Go. Although it is still in early development, it is doing a very great job. Check it here: https://github.com/wader/fq.