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:
wrapmarginare set to 0
expandtabare turned off
fileformatsoptions won't be used
- Files will be written using single line endings
When navigating binary files,
[count]go is useful because it moves the cursor to a byte offset. To get the current location, use
g CTRL-G which displays the current column, line, word, character and byte.
Another good tip is to convert files to the hexdump format using
:%!xxd. It's actually possible to convert a binary to hexdump, edit it, then convert it back to binary using xxd's
-r (revert) flag.
By using anonymous pipes (supported by bash and zsh), it's fairly easy to get Vim to diff files by redirecting the output of
vimdiff <(xxd bin_file_1) <(xxd bin_file_2)