Use the -b option to set binary mode before editing a binary file, for example:
vim -b myfile.bin
If wanted, you can display nonprintable characters in hex, and you can wrap lines:
In normal mode, type g then Ctrl-G to display the byte number at the cursor, or type a byte number then go to jump to that byte (for example, 123go will jump to byte number 123). The first byte in the file has byte number 1.
The following command replaces the buffer with a hex dump:
You can edit the hex bytes, then convert the file back to binary with the command:
The above command reverses the hex dump by converting the hex bytes to binary (the printable text in the right column is ignored).
You can use the ":edit" command, without specifying a file name, to reload the current file. If you have made modifications to the file, you can use ":edit!" to force the reload of the current file (you will lose your modifications).
For more information, read
:help :edit :help :edit! :help 'confirm'
from - http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl#5.8