On 17/03/10 06:43, [email protected] wrote:
Hi,

I am using vim7.2 to edit and save a binary mbr file. It contains 512
bytes. However, inside vim, it shows one additional byte at address
513. After editing, the saved file is one byte more. So it becomes
invalid mbr. I have found a winvi and xvi both claim can edit bindary
file. I still want to see whether I can use vim. So can anyone tell me
how to edit and save binary file safely in vim?

Thanks

Frank


I suspect the additional byte is a linefeed (0x0A) at the very end.

To avoid that, open the file with (from within Vim)

        :e ++bin filename

or (at the shell prompt)

        vim -b filename

This sets 'binary' (locally), which will not only remember the presence or absence of a final LF as the 'eol' local option, but also use the value to remember whether or not to write an end-of-line at the end of the last line when writing the file back to disk.

See also
        :help 23.4
                (the whole section)
        :help hex-editing
        man xxd


Best regards,
Tony.
--
   GALAHAD turns back.  We see from his POV the lovely ZOOT standing by him
   smiling enchantingly and a number of equally delectable GIRLIES draped
around in the seductively poulticed room. They look at him smilingly and
   wave.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to